c++

Use of increments little prob.

Hi i have a problem with this program. Its not too complex, but frustrating. Here is the question......Write a complete c++ program to find the sum of first 5 odd numbers using while loop. Make sure to write an output statement to show the sum. Hint: Variable sum needs to be initialized to 0. Here is what I have so far #include <iostr...

Passing a object by reference in c++

This is a noobie question, but I'm not sure how to pass by reference in C++. I have the following class which sets up a Node and a few functions. class Node { public: Node *next; int data; Node(int dat) { next = NULL; data = dat; } Node* getNext() { return next; } void setNext(Node *n) {...

Will function pointers always initialize to NULL?

I'm using MSVC and it seems like the code below does not crash and the function pointer is initialized to NULL by the compiler. int (*operate)(int a, int b); int add(int a, int b) { return a + b; } int subtract(int a, int b) { return a - b; } int main() { if(operate) //would crash here if not NULL { cout << o...

Resource conflict on ON_UPDATE_COMMAND_UI

I have an EXE class which contains a button resource with ID EXE_BUTTON_RESOURCE ON_UPDATE_COMMAND_UI(EXE_BUTTON_RESOURCE, OnUpdateExeButtonResource) void EXE::OnUpdateExeButtonResource(CCmdUI* pCmdUI) { pCmdUI->Enable(exe_flag); } This EXE application will load another DLL class. DLL class is having a menu item resource wi...

What am I missing? GetLine function (C++)

string GetLine() { char parameter[26] = {NULL}; inFile.getline (parameter,26,' '); return parameter; } Now an example of my input file looks like this: ~in.txt~ BAC BCA(space after the last A) ~End File~ I have to have that space after the A or else my function to get line won't work. Is there a way to not have a space after the ...

Character by Character Input from a file, in C++

Is there any way to get input from a file one number at a time? For example I want to store the following integer in an vector of integers since it is so long and can't be held by even a long long int. 12345678901234567900 So how can I read this number from a file so that I can: vector<int> numbers; number.push_back(/*>>number goes h...

c++ fraction class. overloading operators?

I am making a fraction class for a school project, and my brain is frying. I was told to overload the << and >> operators through the friend keyword. But I'm getting errors for this. I've posted the relevant code here: http://pastebin.com/NgCABGJ2 The errors include: error C2270: '<<' : modifiers not allowed on nonmember functions (thi...

C++ cout fresh array gibberish

When I "cout" an empty array, I get gibberish. Why? int main() { char test[10]; cout << test; return 0; } ...returns some unicode blather. An easy answer I'm sure. ...

When to use QThread::exec()

Hi, I've checked a satisfying explanation but could not find. Usually docs mention that in order to use signals/slots between threads, we need to use event loops and start them by calling exec. However I can see that w/o using exec(), I can still send signals and handle them across threads. What's the exact use of it? ...

Simple C++ project issue with XCode

I am setting up a C++ project in XCode and it seems to not recognize my classes. By default, there is a main.cpp file in the source folder. I added a Node.cpp and Node.h file to this folder, and included the Node.h in my main.cpp file. Unfortunately, it's not recognizing it, it says No such file or directory. Why is it not linkin...

C++ UDP Socket port multiplexing

How can I create a client UDP socket in C++ so that it can listen on a port which is being listened to by another application? In other words, how can I apply port multiplexing in C++? ...

why does directx 9 lack of resources? c++

directx 9 is most library i have found that doesn't have any free tutorials or resources. why is that? ...

Adjust Time to Daylight Saving for localtime C++

I have a piece of optimized function to get the GMT time. I would like to convert it to local time. I would want to call localtime and gmtime function only once to adjust the time to localtime as calling localtime and gmtime multiple times would defeat the purpose of using the optimized function. My idea is adding the difference in time ...

Determine the Internal Path Length of a Tree (C++)

Well I'm down to the last function of my program and I'm done. I've hit another stump that I can't seem to fix on my own. int Tree::InternalPathLength(Node * r, int value) { if(r->left == NULL && r->right == NULL) { return 0; } return value + InternalPathLength(r->left, value+1) + InternalPathLength(r->r...

Using a class that inherits a template class as a constructor parameter in the template class?

Say I have the following: template <class T> class Foo {}; and a descendant class, class Bar : public Foo<some_typename>{}; How would I go about passing Bar to Foo's constructor without Foo.h including Bar.h, if that is even possible? ...

Basic stucture of a C/C++ project (header files and cpp files)

Hello, This is a brain-dead newbie question, but here goes: What determines what files get included in a C/C++ project? My understanding is that the compiler starts with the file that has main() in it and that file will contain #include's to get various h files which contain #include's to other h files and so on until everything is in...

How to get fileindex without using file handle?

The function GetFileInformationByHandle gives us a structure with the values nFileIndexHigh and nFileIndexLow which comprise of a fileIndex. What is this number? Is it the same as the USN? Is there a way to get this fileIndex of a file without opening it (any other method except GetFileInformationByHandle)? ...

Faster to reuse a variable defined in a common scope or redefine it in each inner scope?

C++ specifically, if it matters, but I imagine the answer lies in assembly code somehow. If we have multiple blocks in a common scope (say, a function) which each use a variable of the same type, is it faster to define the variable in the common scope and reinitialise it in each block, or redefine and initialise it in each of the blocks...

Adjust Time to Daylight Saving for localtime C++

I have a piece of optimized function to get the GMT time. I would like to convert it to local time. I would want to call localtime and gmtime function only once to adjust the time to localtime as calling localtime and gmtime multiple times would defeat the purpose of using the optimized function. However, my problem is how could I adjust...

c++ gethostbyaddr with user input

I am writing c++ code for a telnet client. I am having problems getting the host address from the user input. struct in_addr peers; cin>>peers; peerserver = gethostbyaddr((const char*)peers,4,AF_INET); if (peerserver == NULL) exit(0); I am new to c++, can anyone suggest a better way of getting the host addr with user input. Tha...