-
variable "char" problem
I cant get this to work:
Code:
#include <iostream>
using namespace std;
int main()
{
char var_name;
cout<<"Please enter in your name...\n";
cin>> var_name;
cin.ignore();
cout<<"Your name is "<< var_name <<"\n";
cin.get();
}
it compiles without any errors but when i enter in a name it bails. if i sent in one character it'll work correctly. How do i get it so that it could with with multiple characters too?
-
Declare var_name to accept multiple characters.
Code:
char var_name[100];
Next question: how do I get it to accept text with spaces in between? Use getline.
And this.
-
A char type can only store one char, so use a "string" type instead, which can store an unlimited number of chars:
Code:
#include <string>
...
...
string name;
cin>>name;