I am trying to write a progam that takes a full name without spaces and prints the name on separate lines using the getline function. My program is not working. This is what I have:
#include<iostream>
#include<string>
using namespace std;
int main()
{
string str;
str = "Jane Sue Doe";
string str1;
string str2;
string str3;
With standard cin input (i.e. cin >> string;) a space is treated as a newline but with getline all of the data is collected until a newline is read. (Enter key is pressed)
#include <sstream>
//...
string name, first, middle, last;
getline( cin, name ); // expects full name on a single line
istringstream os( name );
os >> first >> middle >> last;