Exercise 2
Swathe — Sat, 2011-03-26 09:33
In our second exercise we moved on to inputting text and printout out the results. The code below asks you for your name and then says hello :)
Open your preferred text editor, input the text in bold below and then save it as name.cpp
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string name;
cout << "Enter your name: " ;
cin >> name;
cout << "Hello "<< name << endl;
return 0;
}
Now in the terminal type:
$ g++ name.cpp -o name
You should now be able to run your newly written program with the command:
$ ./name
Enjoy!
- Login to post comments