Ask coding questions

← Back to all posts
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.

Answered by r3b0rn (27) [earned 5 cycles]
View Answer
RBGoat (2)

@r3b0rn can't, blocked on school chromebook.

r3b0rn (27)

@RBGoat on the website all it says is

#include <iostream>
using namespace std;

int main() {
  cout << "Hello World!";
  return 0;
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.

xfinnbar (82)

You seem to have been following a C# tutorial instead! Try using a C++ one.