problem with <iostream>

W

wesley

Hi All. i am new to C++. I know that in order to use cout, i need to
include <iostream>. I have done this, but i still get errors when i try
to output to the screen. Is there a file that needs to reside in the
same folder as the project? I know that in java, this is the case.
Please help.
Thank Wesley
 
I

Ivan Vecerina

: Hi All. i am new to C++. I know that in order to use cout, i need to
: include <iostream>. I have done this, but i still get errors when i try
: to output to the screen. Is there a file that needs to reside in the
: same folder as the project? I know that in java, this is the case.
I don't think so.

What kind of errors are you seeing ?
I would think that these are compilation errors.

Try starting with the following program:


#include <iostream>
#include <string>
using namespace std;
int main()
{
cout << "Hello" << endl;
string s;
getline( cin, s); // read some user input
return 0;
}
 
E

Eduardo Grajeda

(e-mail address removed) escribió:
Hi All. i am new to C++. I know that in order to use cout, i need to
include <iostream>. I have done this, but i still get errors when i try
to output to the screen. Is there a file that needs to reside in the
same folder as the project? I know that in java, this is the case.
Please help.
Thank Wesley

My guess is that you forgot the namespace, remember that you have to
call cout by:

std::cout << "chocolate" << std::endl;

If you dont want to use 'std::' all the time, read this:
http://www.parashift.com/c++-faq-lite/coding-standards.html#faq-27.5

- Eduardo Grajeda
 
E

Eric Jensen

Hi All. i am new to C++. I know that in order to use cout, i need to
include <iostream>. I have done this, but i still get errors when i try
to output to the screen. Is there a file that needs to reside in the
same folder as the project? I know that in java, this is the case.
Please help.
Thank Wesley

std::cout << "Hello World!" << std::endl;

or

using namespace std;

void writescreen(void) {
cout << "Hello World!" << endl;
}

When using cout the text will be flushed to screen whenever there is a
std::endl or when you call flush.

You might wanna take a look at http://www.cplusplus.com/ref/iostream/

//eric
 
W

wesley

Your program works, i tried something similar, but it did not work, I
left out the #include <string>. The include and cout were underlined by
eclipse. Thanks for your help
 
W

wesley

Thanks guys, i actually did forget the namespace. I am abit rusty with
C++.
Thanks Wes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top