c++

how many strings in a const char* str[] ?

const static char *g_szTestDataFiles[] = { ".\\TestData\\file1.txt", ".\\TestData\\file2.txt", ".\\TestData\\file3.txt", ".\\TestData\\file4.txt", ".\\TestData\\file5.txt", ".\\TestData\\file6.txt" }; Is there way to programmatically determine how many items is in that thing? I could always do #define NUM_DATA...

C++ Compiler Driver Has Stopped Working

Hi, I've downloaded platform SDK and tried using it with Visual Studio 2005. Every time I say built solution it says C++ compiler driver has stopped working!, I also installed Visual Studio 2008, and still face the same problem. this is what it says on the log file, Compiling... Project : error PRJ0002 : Error result -107374151...

Hiding a QWidget on a QToolbar?

Hi, I have directly added some QWidgets to a QToolbar but simply going widget->setVisible(false) did not work. Can someone please give me an example of how to show and hide a widget that is on a QToolbar? Thanks! ...

static variable vs. member

If you have data for a class that will be modified and needs to be retained throughout the program, but is only used in one member function, is it preferred to make that variable a local static variable of the routine that it is in or make it a member of the class? ...

What should I do with this strange error?

Everything is fine and the final problem is so annoying. Compile is great but link fails: bash-3.2$ make g++ -Wall -c -g Myworld.cc g++ -Wall -g solvePlanningProblem.o Position.o AStarNode.o PRM.o PRMNode.o World.o SingleCircleWorld.o Myworld.o RECTANGLE.o CIRCLE.o -o solvePlanningProblem **Undefined symbols: "vtable for Obstacle", re...

C++ error converting a string to a double

I am trying to convert a string to a double. The code is very simple. double first, second; first=atof(str_quan.c_str()); second=atof(extra[i+1].c_str()); cout<<first<<" "<<second<<endl; quantity=first/second; when trying to convert extra, the compiler throws this gem of w...

Hash/key creation function for latitude longitude?

Hello, I have blocks of data associated with latitude/longitude values. I'd like to create a lookup key/hash value from the latitude/longitude value so it can be used as a lookup into a map or something similar. I'm using negative values for West and South... therefore 5W, 10S is represented as -5, -10 in the program. I'd like to...

Thread-safe, lock-free increment function?

UPDATED: Is there a thread-safe, lock-free and available on all Linux distros increment function available in C or C++ ? ...

Is garbage collection automatic in standard C++?

From what I understand, in standard C++ whenever you use the new operator you must also use the delete operator at some point to prevent memory leaks. This is because there is no garbage collection in C++. In .NET garbage collection is automatic so there is no need to worry about memory management. Is my understanding correct? Thanks...

Replay tic tac toe game

So I am trying to program a way to replay a tic tac toe game after someone wins, loses, or ties. So basically my attempt to get replay to work, doesnt work. If player 1 won and I type 1 to replay, it would ask player 2 for their input A basic outline of my code looks like this: do { set entire 2d array to '*' do { ...

Getting the current time (in milliseconds) from the system clock in Windows?

How can you obtain the system clock's current time of day (in milliseconds) in C++? This is a windows specific app. ...

Private static variables to establish invariants

Is it reasonable to use private static variables to establish invariants in your class? Ex: class MovingObject { public: //...Stuff private: // Invariants static const double VELOCITY; // Moving objects always move at this velocity // etc. for any other invariants //... } --------------------------------------------...

Odd behavior of mktime()

Continuing on my attempt to create a DateTime class , I am trying to store the "epoch" time in my function: void DateTime::processComponents(int month, int day, int year, int hour, int minute, int second) { struct tm time; time.tm_hour = hour; time.tm_min = minute; time.tm_sec = second; ...

Creating spherical meshes with Direct x?

How do you go about creating a sphere with meshes in Direct-x? I'm using C++ and the program will be run on windows, only. Everything is currently rendered through an IDiRECT3DDEVICE9 object. ...

Generic object carrier class - C++

I need to create a generic object carrier class. I came up with something simple like template<typename T> class ObjectCarrier { public: const T& item() const { return item_; } void setItem(T& item) { item_ = item; } private: T item_; }; This works well when T has got a default constructor (par...

Localization of string literals

I need to localize error messages from a compiler. As it stands, all error messages are spread throughout the source code as string literals in English. We want to translate these error messages into German. What would be the best way to approach this? Leave the string literals as-is, and map the char* to another language inside the erro...

multi-dimensional array transmit issue

Hello everyone, I am using VSTS 2008 + Native C++ to develop RPC programs (both client and server). I am reading MSDN document for marshalling multi-dimensional array http://msdn.microsoft.com/en-us/library/aa374185%28VS.85%29.aspx I am confused about the following statement, and I am confused about what means offline and online, and ...

Reading from and writing to the middle of a binary file in C/C++

If I have a large binary file (say it has 100,000,000 floats), is there a way in C (or C++) to open the file and read a specific float, without having to load the whole file into memory (i.e. how can I quickly find what the 62,821,214th float is)? A second question, is there a way to change that specific float in the file without having ...

Any tips for a newbie who wants to find a good debugger for C++?

I'm trying to debug my code. I haven't really used a debugger before. I know that in the long run, learning how to use a debugger will be very, very helpful, so I'm trying to find one that suits me. Are there any newbie-friendly debuggers for C++? Ideally with a good GUI... If not, can anyone point me to a good, newbie-friendly guide to...

Why C/C++'s #pragma_once isn't an ISO standard?

I am currently working on a big project and maintaining all those include guards makes me crazy! Writing it by hand is frustrating waste of time. Although many editors can generate include guards this doesn't help much: Editor generates guard symbol based on a filename. The problem occurs when you have headers with the same filename in...