How can I display text in c++?
I am new at c++, and I tried using the code
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."
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.