Program Number One:
Code:
#include <iostream> // cin, cout, <<, >>
#include <string> // string
using namespace std;
//The program starts below
int main()
{
cout << "What is your first name? ";
string firstName;
cin >> firstName;
cout << "\nWelcome to C++, " << firstName <<"!\n";
}
My first question is: Why do I get an error if I modify the cout statement as such:
Code:
cout << \n"Welcome to C++, " << firstName << ;
Program number two:
Code:
#include <iostream>
using namespace std;
#include <string>;
int main()
{
cout << "Hello world!" << endl;
return 0;
}
How come that it does not work if I modify it like this:
Code:
cout << "Hello world!" << ;
...but it works if I change it to this:
Code:
cout << "Hello world!" << "\n";
(Note the first cout statement in program number one)
What rules am I violating?
I apologize for asking such basic questions, but the book I am learning from does not explain it.
Thanks in advance.
Best