【问题标题】:How can I std::getline() a string?我怎样才能 std::getline() 一个字符串?
【发布时间】:2015-03-17 20:17:48
【问题描述】:

假设我有这个字符串

string myString = "This is a test string:value1/value2/value3/"

我该如何做这样的事情:

getline (myString, temp, '/');

我正在考虑将output << myString 写入文件,然后使用 getline (output, temp, '/') 像往常一样,但我认为应该有其他方法。 谢谢,请帮帮我。

【问题讨论】:

    标签: c++ c++11 visual-c++


    【解决方案1】:

    getline 从流中提取;所以你想把你的字符串放到string-stream:

    #include <sstream>
    
    std::stringstream ss(myString);
    getline(ss, temp, '/');
    

    【讨论】:

      猜你喜欢
      • 2015-04-13
      • 1970-01-01
      • 2011-01-10
      • 1970-01-01
      • 2014-12-14
      • 1970-01-01
      • 1970-01-01
      • 2021-01-23
      相关资源
      最近更新 更多