使用c ++逐行读取字符串 [英] read an string line by line using c++
本文介绍了使用c ++逐行读取字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字符串
有多行,我需要逐行读取。
I have a string
with multiple line and I need to read it line by line.
Please show me how to do it with a small example.
例如:我有一个字符串 string h;
Ex: I have a string string h;
h将是:
Hello there.
How are you today?
I am fine, thank you.
我需要提取
今天你好吗?
和我很好,谢谢。
不知何故。
I need to extract Hello there.
, How are you today?
, and I am fine, thank you.
somehow.
推荐答案
#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 ++逐行读取字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文