I am trying to make a program that you can enter in a word like:
cout<<"What is your name?<<endl;
cin>>name;
cout<<"Your Name is "<<name<<" !"<<endl;
Can anyone help me?
Thanks
I am trying to make a program that you can enter in a word like:
cout<<"What is your name?<<endl;
cin>>name;
cout<<"Your Name is "<<name<<" !"<<endl;
Can anyone help me?
Thanks
Code:#include <iostream.h> void main() { char name[]; cout << "What is your name? "; cin >> name; cout << "Your name is " << name << "."; return; }
Wowowowow! You can't just create a pointer and then use it to input text! That pointer can point on anything!
// Gliptic
Erm.
Make that char name[1];
Plenty of space! You can put in a null terminator at least!
// Gliptic
Okay, try this:
Please, if you spot a mistake, make sure you correct it.PHP Code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name;
cout << "What is your name? ";
cin >> name;
cout << "Your name is " << name << "." << endl;
return 0;
}
hth
-nv
She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."
When in doubt, read the FAQ.
Then ask a smart question.
What? A mistake? Haven't seen any
but hey.. why nobody have told me about that string-library?
There are two views on the string library. One, it hides too much from the programmer and uses confusing syntax with iterators etc. On the other hand, if you understand what is happening behind the scenes by the class methods, then it can make life a lot easier. Because it can make life a lot easier and because you can do a lot by blind trust some people start with the string class so you don't have to monkey with the functions in string.h to manipulate c_style strings. Up to date compilers probably come equipped with the string class, or equivalent, but "older" compilers you can readily come across won't have it.