Originally Posted by
max.diems
C++
Version 1: Do not write results to file
Code:
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
string username = "";
int main(int argc, char *argv[]);
int main(int argc, char *argv[]){
cout << "Hi! What's your name? ";
cin >> username;
cout << "Hello, " << username << "! Welcome to Ubuntu!\n";
return 0;
}
No reason to make it so complicated:
Code:
#include <iostream>
int main()
{
std::string username;
std::cout << "Hi! What's your name? ";
std::getline(std::cin, username);
std::cout << "Hello, " << username << "! Welcome to Ubuntu!" << std::endl;
return 0;
}
I don't like using namespaces. And it's with getline instead of cin, so the name can contain spaces.
Bookmarks