How do you handle strings in C++ . Mainly Input. Now You might be thinking that I should post this on the beginner forum but I am actually quite intermediate in C++ . It's just that I am 13 and I am teaching myself C++ and Java. I use Microsoft Visual C++ Compiler 2010. I have written this code, it compiles but doesn't work.
#include <iostream>// input and output
#include <string> //do you declare this like it is?
using namespace std;//namespace standard
string name; //is this how you make a string?
int main()//the main body
cout<<"What is your name?";//output
cin>>name;//input to string
cout<<"Hello" << name;//output
The program works until it needs to output hello name.
Any help would be appreciated.
//Avoid using namespace std. It is a bad practice
//Globals are usually a bad practicce too
std::string name; //local variable
std::cout << "What is your name?" << std::endl; //New line after question
std::cin >> name;
std::cout << "Hello, " << name; //Should work. note whitespace at the end of literal.
Your code should work. How it is not working? What output is?