Central Queensland Linux User Group

  • home
  • faq's
  • hints, help and information
  • links
  • linux programming
  • media
  • events
  • about us
Home

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!

  • Exercises
  • Login to post comments

Navigation

  • Recent posts

User login

  • Request new password

Events

Coming to a meeting soon!
Meetings for 2020
more

Who's online

There are currently 0 users and 0 guests online.
  • home
  • faq's
  • hints, help and information
  • links
  • linux programming
  • media
  • events
  • about us