tags:

views:

68

answers:

1

Hi,

I am trying to read in two strings separated by a space.

cin>>a; cin>>b;

This should technically work. I have also used getline but it doesnt seem to work. It reads in some of the inputs and gets stuck on others

Edit: Added C++ tag, kept C tag since it's part of the original post.

+3  A: 

This:

#include <iostream>
#include <sstream>

int main()
{
    std::istringstream iss("wrgl zrgl");
    std::string s1, s2;
    iss >> s1 >> s2;
    std::cout << '"' << s1 << "\" \"" << s2 << "\"\n";
    return 0;
}

compiles, runs, and prints "wrgl" "zrgl" on my machine.

sbi