![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Aug 2004
Location: Cloud #9
Posts: 47
Rep Power: 0
![]() |
What is the difference between... (hello world-noob)
std::cout and cout?
Im using Orielly's book and he's using Borland, but Im using DevCpp. Borland won't properly download for some reason... and I like DevCpp. 'std::cout' doesn't work in Dev, and when I change it to simply 'cout', it also doesn't work. Here's the one the book wants me to use: #include <iostream>
int main()
{
std::cout << "Hello World\n";
return (o);
}DevCpp highlights the std::cout line and says down below "'cout' is not a member of 'std'". Here is one from Dev itself and as you can see, it likes 'cout': #include <iostream>
using namespace std;
int main (int argc, char *argv[])
{
char quit;
quit = '\0';
while (quit != 'q')
{
cout << "Hello ! This is a console app." << endl;
cout << "To create a console, go to Project Options and select" << endl;
cout << "\'Win32 Console\'." << endl;
cout << "Press q to quit " << endl;
cin >> quit;
}
return 0;
}I welcome your insight. Last edited by Insomniac; May 30th, 2005 at 3:47 AM. |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 6
![]() |
C++ has something called namespaces, and cout belongs to the std library. so you have to either say std::cout explicitly every time you use it, or you have to put the statement
using namespace std; at the top of your code. you'll see the double-colon used when you get into classes and such. i know, that problem was a bitch for me at one time as well. and as for it coming out bad we have tags for code as such we also have quote tags too
__________________
i put on my robe and wizard hat... Have you ever heard of Plato, Aristotle, Socrates?...Morons. |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Aug 2004
Location: Cloud #9
Posts: 47
Rep Power: 0
![]() |
thank you ninja,
edit: Got it.
__________________
From an IBM Thinkpad T43 - 14.1" SXGA+ - ATI 64 MB X300 - Sonoma 760 - 2 GB RAM - 80 GB HD 5400 - IBM ABG II - FC3, Ubuntu & XPee DevC++, and Macromedia's - Dreamweaver & Flash Pro and a little Adobe Illustrator & Photoshop Sleep? Sleep is for the weak.:cool: Last edited by Insomniac; May 29th, 2005 at 3:20 PM. |
|
|
|
|
|
#4 |
|
Programmer
Join Date: Aug 2004
Location: Cloud #9
Posts: 47
Rep Power: 0
![]() |
I hate to ask this because I once found the answer to it.. and now I can't after doing a search.
After compiling and executing the program the window doesn't stay open. Any suggestions? I tried the system("PAUSE"); line.. but it did nothing that I could see. #include <iostream>
using namespace std;
int main()
{
cout << "Hello World\n";
return 0;
}
__________________
From an IBM Thinkpad T43 - 14.1" SXGA+ - ATI 64 MB X300 - Sonoma 760 - 2 GB RAM - 80 GB HD 5400 - IBM ABG II - FC3, Ubuntu & XPee DevC++, and Macromedia's - Dreamweaver & Flash Pro and a little Adobe Illustrator & Photoshop Sleep? Sleep is for the weak.:cool: Last edited by Insomniac; May 30th, 2005 at 3:49 AM. |
|
|
|
|
|
#5 |
|
Programmer
Join Date: May 2005
Posts: 34
Rep Power: 0
![]() |
it's because you have to include <cstdlib> for system("PAUSE"); also you can do cin.get();
|
|
|
|
|
|
#6 |
|
Programmer
Join Date: Aug 2004
Location: Cloud #9
Posts: 47
Rep Power: 0
![]() |
Thanks Chris,
![]() where do I put that? I tried cin.get(); in two different places that I thought were right: #include <iostream>
using namespace std;
int main()
{
cout << "Hello World\n"; //prints "Hello World" on the screen
return 0;
}
cin.get();AND #include <iostream>
using namespace std;
int main()
{
cout << "Hello World\n"; //prints "Hello World" on the screen
return 0;
cin.get();
}The book makes no reference to that line at all. :o
__________________
From an IBM Thinkpad T43 - 14.1" SXGA+ - ATI 64 MB X300 - Sonoma 760 - 2 GB RAM - 80 GB HD 5400 - IBM ABG II - FC3, Ubuntu & XPee DevC++, and Macromedia's - Dreamweaver & Flash Pro and a little Adobe Illustrator & Photoshop Sleep? Sleep is for the weak.:cool: Last edited by Insomniac; May 30th, 2005 at 3:50 AM. |
|
|
|
|
|
#7 |
|
Programming Guru
![]() |
the second one should be correct and it probably makes no refernce to it as well they dont want to over complicate things.
__________________
"Put your hand on a hot stove for a minute, and it seems like an hour. Sit with a pretty girl for an hour, and it seems like a minute. THAT'S relativity." - Albert Einstein |
|
|
|
|
|
#8 | |
|
Programmer
Join Date: Aug 2004
Location: Cloud #9
Posts: 47
Rep Power: 0
![]() |
Quote:
![]()
__________________
From an IBM Thinkpad T43 - 14.1" SXGA+ - ATI 64 MB X300 - Sonoma 760 - 2 GB RAM - 80 GB HD 5400 - IBM ABG II - FC3, Ubuntu & XPee DevC++, and Macromedia's - Dreamweaver & Flash Pro and a little Adobe Illustrator & Photoshop Sleep? Sleep is for the weak.:cool: |
|
|
|
|
|
|
#9 |
|
Programmer
Join Date: Aug 2004
Location: Cloud #9
Posts: 47
Rep Power: 0
![]() |
With a little extra searching I found what works.
![]() getchar(); immediately following the cout statement. Yea! Ok, now to the understanding part.. what is this line saying exactly? 'get character' and somehow it waits for user input?
__________________
From an IBM Thinkpad T43 - 14.1" SXGA+ - ATI 64 MB X300 - Sonoma 760 - 2 GB RAM - 80 GB HD 5400 - IBM ABG II - FC3, Ubuntu & XPee DevC++, and Macromedia's - Dreamweaver & Flash Pro and a little Adobe Illustrator & Photoshop Sleep? Sleep is for the weak.:cool: Last edited by Insomniac; May 30th, 2005 at 3:52 AM. |
|
|
|
|
|
#10 | |
|
Newbie
Join Date: Jan 2005
Posts: 21
Rep Power: 0
![]() |
Quote:
Actually, neither of those are correct. As soon as the code encounters the return, the function exits. cin.get() is never executed. The correct code would be as follows: int main() { cout << "Hello World\n"; //prints "Hello World" on the screen cin.get(); //Wait for user input return 0; //Exits funciton } |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|