how do I set it that I am able to enter more than one char ex:hello, right now all I can enter is ex: a, or b ect...
I just started programming.
how do I set it that I am able to enter more than one char ex:hello, right now all I can enter is ex: a, or b ect...
I just started programming.
Post code showing how you are reading-in single characters and then I can show you how to read in strings.
thanks for the quick response I'm not used to that.
here is the code
Code:# include <iostream.h> int main () { int number; char letter; cout <<"please enter one letter." cin >> letter; cout << "please enter your age." cin >> number; cout << "this is the name you have entered." << letter; cout << this is the age you have entered." << number; return 0; }
I was told to include <string.h> what is that supposed to do?
string letter
I am against the teaching of evolution in schools. I am also against widespread
literacy and the refrigeration of food.
will that solve my problem?
char name[50];
cout<<"Enter your name: ";
cin.get(name, 50);
Or
char name[50];
cout << "Enter a name:";
cin >> name;
cout << "You entered:" << name << endl;
You should learn about strings, either as an array of char's or using the string library <cstring>
none...
you can also do
scanf("%s",&name)
with char[30]
[30]-can be changed to any number but that might cause a glich when you enter more than your number in [].hope it helps
Last edited by master2000; 12-15-2002 at 09:15 AM.
is this c++
and this regular cCode:char name; getline name;
?????????????????????????????????????????????Code:char name[50]; cin name;
Wrong. cin is an istream object. In other words it is a c++ class. Since this is C++ you should use a string. However, if speed and memory consumption is an issue (i doubt that it is here) then use a array. You can't hold a string in a single char. A char only holds 1 byte of data (one letter).
No, the string type is located in <string>Originally posted by ammar
You should learn about strings, either as an array of char's or using the string library <cstring>
<cstring> is functionaly equivalent to <string.h>