I can't get any iostream functions to work, when I run the program there is no output except for stdlib.h functions.
My source code is posted the the tread : "Can't figure out this darn linker!"
I can't get any iostream functions to work, when I run the program there is no output except for stdlib.h functions.
My source code is posted the the tread : "Can't figure out this darn linker!"
DJGPP-Complier
Windows 98-(Shouldn't need to explain)
I like plants.
Can't find that thread.
You might wanna try #include <iostream> if its not there already.
Also make sure your >> are facing the right direction.
std::cout << "Hi\n";
std::cin >> x
Those who live by the sword get shot by those who don't.
I can C.
Compiler: gcc
Thread is here.
Use the standard version of Iostreams (as zdude mentioned), and replace / with \ in control characters (\n, \t, not /n, /t).
The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.
I changed all the slashes and tried the standard versions of cout<< and cin>>, but it still will not work.
I'm using Dev-C++ version 4, if it's the complier, please let me know.
DJGPP-Complier
Windows 98-(Shouldn't need to explain)
I like plants.
Post your most recent code.
>>I'm using Dev-C++ version 4, if it's the complier, please let me know.
Nope I use dev-c++ 4, the same thing happened to me with with a diferent header file. I added like 500 header files and it didn't work afterward so I reinstalled it(hint hint). And it works just fine now.
I'll try that zornthrohacker, but here is the code
Here is DineOut.h:Code:#include <iostream.h> #include <stdlib.h> #include <DineOut.h> int main() { int DineOut; int YearBorn; int FinalNumber; int HaveYouHadBirth; std::cout<<"DINING OUT MATHEMATICS.\n\n"; system("PAUSE"); std::cout<<"\n"; cout<<"\t"<<"Here is some really neat math!\n"; cout<<"\a\v"; cout<<"First, enter the number of times that \n"; cout<<"you would like to dine out a week.\n"; cout<<"(This number must be >1 but <10.)"; cout<<"\n\n\t"; cin>>DineOut; cout<<"\n\n"; cout<<"Now, we will multiply this number by 2.\n"; cout<<"(Just to be bold!)"; cout<<"\n\n\t"; cout<<DineOut<<" x 2 = "<<Twice(DineOut)<<"\n\n"; system("PAUSE"); cout<<"\n\n"; cout<<"Now, we will add 5 for Sunday."; cout<<"\n\n\t"; cout<<DineOut<<" + 2 = "<<AddFive(DineOut)<<"\n\n"; system("PAUSE"); cout<<"\n\n"; cout<<"Now Multiply it by 50."; cout<<"\n\n\t"; cout<<DineOut<<" x 50 = "<<FiftyTimes(DineOut)<<"\n\n"; system("PAUSE"); cout<<"\n\n"; cout<<"Now, if you've had your birthday, please press 1. "; cout<<"\n"<<"If you haven't, please press two."; cout<<"\n\t"; cin>>HaveYouHadBirth; if (HaveYouHadBirth==1) { cout<<"\n\n"; cout<<"Since you've had your birthday, we'll add 1753."; cout<<"\n\n\t"<<DineOut<<" + 1753 = "<<HadBirth(DineOut); cout<<"\n\n"; system("PAUSE"); } else if (HaveYouHadBirth==2) { cout<<"\n\n"; cout<<"Since you haven't had your birthday, we'll add 1752."; cout<<"\n\n\t"<<DineOut<<" + 1752 = "<<NotHadBirth(DineOut); cout<<"\n\n"; system("PAUSE"); } else { cout<<"You have not entered a valid number.\a\n\a\n"; system("PAUSE"); cout<<"This program will therefore not work correctly."; } cout<<"\n\n"; cout<<"Now, enter the year you were born."; cout<<"\n\n\t"; cin>>YearBorn; cout<<"\n\n"; cout<<"Now, we will subtract the year you were born."; FinalNumber=DineOut - YearBorn; cout<<"\n\n\t"<<DineOut<<" - "<<YearBorn<<" = "<<FinalNumber; cout<<"\n\n"; system("PAUSE"); cout<<"\n\n"; cout<<"Finally, you should be left with a three digit number."; cout<<"\n\t"<<FinalNumber; cout<<"The first digit is the number of times you would like to\n"; cout<<"dine out a week.\n"; cout<<"The last two numbers are:\n"<<"duh duh duh duuuuuuuuuhhhhhhh!!!\n"; cout<<"YOUR AGE!!! HAHAHA!!!"; system("PAUSE"); return 0; }
Code:class DineOut { public: double FiftyTimes(double x); double Twice(double x); double AddFive(double x); double HadBirth(double x); double NotHadBirth(double x); protected: double x; }; double FiftyTimes(double x) { return x*50; } double Twice(double x) { return x*2; } double AddFive(double x) { return x+5; } double HadBirth(double x) { return x+1753; } double NotHadBirth(double x) { return x+1752; }
DJGPP-Complier
Windows 98-(Shouldn't need to explain)
I like plants.
reinstalling did not work
DJGPP-Complier
Windows 98-(Shouldn't need to explain)
I like plants.
<iostream> and <cstdlib> are the correct C++ way to include those features. Further, your own headers should be in ""s so the compiler will search the source directory for the header.Code:#include <iostream> #include <cstdlib> #include "DineOut.h"
Further, if you use <iostream>, you either need to have the line "using namespace std;", or you need std:: before *every* instance of cout and cin, not just a couple of them.
changed to:
...Code:#include <iostream> #include <cstdlib> #include "DineOut.h" int main() { using namespace std;
It still will not work.
DJGPP-Complier
Windows 98-(Shouldn't need to explain)
I like plants.
Well, try out this:
Does THAT work?Code:#include <iostream> #include <cstdlib> int main(){ using namespace std; cout << "Hello World" << endl; system("pause"); }
One thing to note; cout can take as long as it wants to actually write to the screen. endl explicitly forces it to write to the screen (it flushes the output). So the above code will ALWAYS have the following output:
Hello World
Press any key to continue.
But this code:
MIGHT have that output, but might also have this output:Code:#include <iostream> #include <cstdlib> int main(){ using namespace std; cout << "Hello World" << "\n"; system("pause"); }
Press any key to continueHello World
Last edited by Cat; 07-03-2003 at 03:13 PM.
I even tried that, it must be something to do with the complier, or maybe iostream.h got messed up.
DJGPP-Complier
Windows 98-(Shouldn't need to explain)
I like plants.
Is it actually compiling and not printing, or is there some compiler error?
The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.
It's actually compiling and not printing, it used to have a linker problem, but it's not showing one anymore.
Is there anyone who can try the program and see if it works for them?
DJGPP-Complier
Windows 98-(Shouldn't need to explain)
I like plants.
If you don't have any std::endl's, put a std::cout.flush() in right before system("pause")... See if that does anything.
The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.