Skip whitespaces with getline

前端 未结 2 735
夕颜
夕颜 2021-02-04 19:13

I\'m making a program to make question forms. The questions are saved to a file, and I want to read them and store them in memory (I use a vector for this). My questions have th

相关标签:
2条回答
  • 2021-02-04 19:56

    Look at this and use:

    ss >> std::ws;
    getline(ss, question);
    
    0 讨论(0)
  • 2021-02-04 20:00

    No getline doesn't ignore whitespaces. But there nothing to stop you adding some code to skip whitespaces before you use getline. For instance

        while (ss.peek() == ' ') // skip spaces
            ss.get();
        getline(ss, question);
    

    Soemthing like that anyway.

    0 讨论(0)
提交回复
热议问题