Orbaneqtrx5
August 21st, 2010, 05:27 PM
I just started learing C++ on my own and use Ubuntu (GCC) to compile and run. I compiled the following program using GCC and works fine, but when I tried running it on Windows using Dev++ or VC++ as soon as i input my name and press enter the prompt will exit. I don't know what is the difference from linux to windows maybe someone can help me out... Thanks beforehand :
#include <iostream>
#include <string>
using namespace std;
int main ()
{
cout << "Please enter your name :";
string name;
cin >> name;
const string greeting = "Hello" + name + "!";
const string spaces (greeting.size(), ' ');
const string second = "* " + spaces + " *";
const string first (second.size(), '*');
cout << endl;
cout << first << endl;
cout << second << endl;
cout << "* " + greeting + " *" << endl;
cout << second << endl;
cout << first << endl;
return 0;
}
#include <iostream>
#include <string>
using namespace std;
int main ()
{
cout << "Please enter your name :";
string name;
cin >> name;
const string greeting = "Hello" + name + "!";
const string spaces (greeting.size(), ' ');
const string second = "* " + spaces + " *";
const string first (second.size(), '*');
cout << endl;
cout << first << endl;
cout << second << endl;
cout << "* " + greeting + " *" << endl;
cout << second << endl;
cout << first << endl;
return 0;
}