我有一个 std::string
多行,我需要逐行阅读。
请用一个小例子告诉我如何做到这一点。
例如:我有一个字符串 string h;
h 将是:
Hello there.
How are you today?
I am fine, thank you.
我需要提取 Hello there.
, How are you today?
, 和 I am fine, thank you.
不知何故。
最佳答案
#include <sstream>
#include <iostream>
int main() {
std::istringstream f("line1\nline2\nline3");
std::string line;
while (std::getline(f, line)) {
std::cout << line << std::endl;
}
}
关于c++ - 使用 C++ 逐行读取字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5059049/