getline

Pages: 12
LOL @ Bazzy

I'm just kidding around. Apparently gmghulamabbas works best with half char arrays and half strings, though.

Seriously, though...

If you like char arrays so much why don't you program in C instead of C++?


char arrays are just as much a part of C++ as they are of C. Just because the STL exists doesn't mean that it has to (or even should) be used for everything all the time.
dear Bazzy
i used both char for name and string for adress and its right but if i take both as a string then it does not work. i want to know the reason of this.
thanks
What are you using to get input when both are strings?
getline or cin.getline ?
i m using getline (cin,string varible name)

it does not give any error but output is not right.
b/c i want to write complete name and complete adress.

plz tell me its reason thanks
By modifying your sourcecode to get strings i have this:
1
2
3
4
5
6
7
8
9
10
11
string name;
string address;

cout<<"Enter your complete name: ";
getline (cin,name);

cout<<"Enter your complete address: ";
getline (cin,address);

cout<<"\n\n"<<name<<endl;
cout<<address<<endl<<endl;
Which works fine, what problems do you have with output?
Dear Bazzy in disply it is giving me just my name not my adress.

When i give the input after writing my complete name i have to click enter twice rather than once. why its so ?

after giving input when it display output then it give just my name and adress skip simply.

why its so.?

Thanks
You don't have to press enter twice, the second time you pressed it was for address input. If you don't see "Enter your complete address: " being displayed, you may have to call cout.flush() after it (before getting address)
Topic archived. No new replies allowed.
Pages: 12