Standard entry in C+++



  • Two variables shall be considered from the standard flow: int and string. The introduction is divided by the end-of-line symbol, the variable string may contain gaps. I'd like to avoid a subtle type code:

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

    I'd like to decide elegantly, like:

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

    But I guess there's a need to build a cin. Tell me how to make it beautiful, scanf is not welcome.



  • For example, such a design could be organized

    int i;
    string s;
    getline((cin >> i).ignore(100, '\n'), s);
    

Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2