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...
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)
{...
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...
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...
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 ...
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...
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...
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.
...
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?
...
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...
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++?
...
directx 9 is most library i have found that doesn't have any free tutorials or resources.
why is that?
...
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 ...
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...
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?
...
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...
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)?
...
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...
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...
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...