Two variables must be read from the standard stream: int and string. The input is separated by the end-of-line character, the variable string probably contains spaces. I would like to avoid clumsy view code:

int i; string s; cin >> i; //перед считыванием строки приходится хавать символ конца строки cin.get(); //считываем строку полностью (возможно, сторока содержит пробелы) getline(cin, s); 

I would like to solve elegantly, like:

 int i; string s; cin >> i >> s; 

but, apparently, before this somehow you need to configure the cin object. Tell me how to make beautiful, scanf is not welcome.

    2 answers 2

    It is possible, for example, to organize such a construction

     int i; string s; getline((cin >> i).ignore(100, '\n'), s); 
       int a; char b[10]; cin>>a>>b; cout<<"int a:"<<a<<"char b:"<<b; 

      cin & cout do not want to work with string, so you can read it into char and then convert it to string.

      • I want to squeeze something out of cin, or play with iterators of input streams. - morin