c++

If you only have a hammer...or

I need to download some csv files over http from the internet, parse it and convert it to a more useful fomat. Eventually a C++ program will consume the data. A few years ago, I would be pulling out my Perl books and start writing Perl scripts to do the downloading and parsing. But now with Boost and Qt I can do the download, parsing, an...

Creating multiple instances of global statics in C++?

One of the libraries we are using for our product uses a singleton for access to it. I'm pretty sure it's implemented as a static instance (it isn't open source). This works well for a single document application, but our app may have more than one document loaded. I'm assuming access to the instance is written something like this: Inst...

Is this the correct way to overload the left-stream operator? (C++)

This function declaration gives me errors: ostream& operator<<(ostream& os, hand& obj); The errors are: error C2143: syntax error : missing ';' before '&' error C4430: missing type specifier error C2065: 'os' : undeclared identifier error C2065: 'obj' : undeclared identifier error C2275: 'hand' : illegal use of this type as an expres...

How to mix php and C++ for user authenication?

Hello i'm making a program to get the names of users on my website and use that log for my programs so only registered people can login. How would I go about doing this? ...

What does "cannot convert 'this' pointer from 'const hand' to 'hand &' mean? (C++)

The error occurs when I try to do this friend std::ostream& operator<<(std::ostream& os, const hand& obj) { return obj.show(os, obj); } where hand is a class I've created, and show is std::ostream& hand::show(std::ostream& os, const hand& obj) { return os<<obj.display[0]<<obj.display[1]<<obj.display[2]<<obj.display[3]<<obj.di...

What does "warning: not all control paths return a value" mean? (C++)

The exact warning I get is warning C4715: 'hand::show' : not all control paths return a value and hand::show is std::ostream& hand::show(std::ostream& os) const { if(side == left) { return os<<display[0]<<display[1]<<display[2]<<display[3]<<display[4]; } if(side == right) { return os<<display[4]<<display...

declare a array of const ints in C++

Hi, I have a class and I want to have some bit masks with values 0,1,3,7,15,... So essentially i want to declare an array of constant int's such as: class A{ const int masks[] = {0,1,3,5,7,....} } but the compiler will always complain. I tried: static const int masks[] = {0,1...} static const int masks[9]; // then initializing ...

How can I fix an int-to-bool warning in C++?

I get a warning in MSVC++ when I try to read an integer from a file and make a bool variable equal it. accessLV[i] = FileRead(file1, i + 1); (accessLV is an array of bools, FileRead is a function I made to decrease the syntax involved in reading from a file, i is because the statement is within a for loop) I've tried using a static_c...

C++ code to get line of file and read the second word of the line?

#include <iostream> #include <string> #include <fstream> using namespace std ; string strWord( int index , string line) { int count = 0; string word; for ( int i = 0 ; i < line.length(); i++) { if ( line[i] == ' ' ) { if ( line [i+1] != ' ') { ...

Best Data Structure for this Multithreaded Use Case: Is Intrusive List good?

I need to design a data structure that supports the following operations: search element in the data structure based on a key that is an interval. For example the value within interval 1-5 may be 3, from 6-11 may be 5 and so on. The intervals are contiguous and there is no overlap between them. find previous and next interval - this i...

Nested functions are not allowed but why nested function prototypes are allowed? [C++]

I was reading the linked question which leads me to ask this question. Consider the following code int main() { string SomeString(); } All says, compiler takes this as a function prototype and not as a string object. Now consider the following code. int main() { string Some() { return ""; } } Compiler said...

msvc9, iostream and 2g/4g plus files

Doing cross platform development with 64bit. Using gcc/linux and msvc9/server 2008. Just recently deployed a customer on windows and during some testing of upgrades I found out that although std::streamoff is 8 bytes, the program crashes when seeking past 4G. I immediately switched to stlport which fixes the problem, however stlport se...

How to distribute a program on an unreliable cluster?

What I'm looking for is any/all of the following: automatic discovery of worker failure (computer off for instance) detection of all running (linux) PCs on a given IP address range (computer on) ... and auto worker spawning (ping+ssh?) load balancing so that workers do not slow down other processes (nice?) some form of message passing ...

Why is MinGW very slow?

I'm using Code::Blocks IDE with Gcc/minGW on Windows and I'm trying to build a wxWidgets application which has ca. 20k lines and 40 source modules. And it builds very very slow. Compiling a cpp module lasts 2-5 seconds, and linking lasts even 2-3 minutes. It's a portable code, this code on Linux compiles very fast. I can't follow the bu...

How can I compile C/C++ code in PHP on the Windows platform?

Can anyone help me with the compilation of C++ code in PHP on the Windows platform? I am using Microsoft Visual C++ 6.0. I have tried the following options which I knew, but none of them work: system('test.c') exec('test.c') The file 'test.c' has been placed in my php/www/ folder. I need to first compile the code, which makes test....

Having trouble enabling verticle scrolling in edit box

I'm using Visual Studio 2005 and programming a dialog-based MFC application in C++. I have an edit box and I'm trying to make it auto-scroll. When I make auto vscroll true, it still won't auto-scroll when I have too many lines in my edit box. Any ideas in what could be wrong? Is there maybe some code line I have to add to my edit box? ...

C++: Assigning values to non-continuous indexes in vectors?

If I want to declare a vector of unknown size, then assign values to index 5, index 10, index 1, index 100, in that order. Is it easily doable in a vector? It seems there's no easy way. Cause if I initialize a vector without a size, then I can't access index 5 without first allocating memory for it by doing resize() or five push_back()'...

Is clrscr(); a function in C++?

I've looked everywhere for this function and cannot find the header files to make this work. It says clrscr() undeclared which brings me to the question. Is clrscr(); a fuction in C++? ...

Need help adding scroll bar to edit box

I'm making an MFC dialog-based application in Visual C++ 2005. I added a scroll bar to an edit box. How do I program the scroll bar to make it work? ...

«F(5)» and «int x; F(x)» to call different functions?

I'd like to write two distinct functions to handle a constant value and a variable of a given type (viz., int). Here is the example test case: int main(void) { int x=12; F(5); // this should print "constant" F(x); // this should print "variable" } I thought it would be enough to define: void F(int v) { cout...