How can I display text in c++?
RBGoat (2)

I am new at c++, and I tried using the code

console.WriteLine("Hello World");

but it did not work. Instead, it produced an error message saying something about the dot not working? It's in line 3.

My goal was simply for it to say "Hello World."

EDIT: Answered/resolved.

You are viewing a single comment. View All
Answered by r3b0rn (27) [earned 5 cycles]
View Answer
TurtleAndrew (211)

For some more detail on the cout syntax, you can do it with one argument:

cout << "hello world";

But also more then one:

cout << "hello world 1" << "hello world 2" << "hello world 3";

You can also have it go down a line by adding "endl" (without the quotes) instead of text:

cout << "hello world" << endl;

Note that if you don't have:

using namespace std;

that you will need to add "std::" (without the quotes) before "cout" and "endl" (without quotes):

std::cout << "hello world" << "hello world 2" << std::endl;

You can also pass in float, int, string, ect... variables instead of text.

int testing = 1;
cout << "The value of testing: " << testing << endl;

All the code shown should go inside of the "int main" function except for "using namespace std;".

I hope this will help you understand some of the details of the cout syntax.