getting user input past a space

closed account (2EwbqMoL)
I've tried a few things to accomplish this, ranging from c to c++ io functions (cin and scanf) and c++ and c-style (array) strings...

if I use c# or any of the .NET languages, its just a standard part of the input command (Console.ReadLine();)

for example, I'm tyring to write a small simple test app that asks for a users full name (first and last) and spits it back out at them...

right now the code I have is
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <string>
using namespace std;

string input;

int main(){
	cout << "Whats your name?: ";
	cin >> input;
	cout << "\nHi " << input << " How are you doing?\n";
	system("PAUSE");
	return 0;
}


nothing too complicated at all, Im just trying to get input to take in data after the space -- theres nothing in my code showing this, but thats only because Im not exactly sure what I need to do to accomplish this goal.

I figured switching from char to string would solve it on its own, but perhaps its a problem with cin???
there is the getline function

1
2
string str;
getline (cin, str);
Last edited on
closed account (2EwbqMoL)
thanks a lot, Im surprised I didnt already know about that...
Topic archived. No new replies allowed.