Click to See Complete Forum and Search --> : cin problem II SIMPLE
WP
Jan 2nd, 2001, 03:23 AM
Another question: how can I use cin with strings?
string data;
cin>>data; //gives an error
WP
parksie
Jan 2nd, 2001, 05:12 AM
If you want to use strings then you need to use the proper STL iostreams library:
#include <iostream> /* No .h extension! */
#include <string>
using namespace std;
if you want to be able to get more than one word(like if somebody typed "hello world" hello would be the only one gathered), do this
string str;
getline(cin,str);
cout << str;
WP
Jan 3rd, 2001, 04:01 AM
but the user has to press twice on the return button
WP
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.