如何在 的开头<x>和结尾<y>之间更改带有文件输出的字符串的值
How do I change the value of a string with the output of a file between the start of <x> and the end of <y>
我正在尝试将字符串的值设置为OUTPUT
,为文件中的某些文本。基本上在文件中,我想设置OUTPUT
的值,其中包含两个字符串之间的所有文本TRACE,0000
和,Time,0
例如:
random text in the file
random text in the file
random text in the file
TRACE,0000
stuff
goes
in
here
Time,0
random text in the file
random text in the file
random text in the file
OUTPUT
的值是:
TRACE,0000
stuff
goes
in
here
Time,0
我只是不知道如何处理这个问题。如果有人能帮助我,将不胜感激。
干杯。
以下示例代码可能会对您有所帮助。如代码所示,检查过程将在while-loop
中消失。我希望它能帮助你。
#include<iostream>
#include<fstream>
#include<string>
int main()
{
// other things to do
std::fstream readFile;
readFile.open("file");
if (!readFile.is_open()){
std::cout<<"Files couldn't be open!";
return 1;
}
std::string line = "";
bool start_read = false;
while (getline(readFile, line)) {
if(line == "TRACE,0000")
start_read = true;
else if (line == "Time,0"){
std::cout<<line<<std::endl;
break;
}
if(start_read)
std::cout<<line<<std::endl;
}
// remaining things to do
return 0;
}
相关文章:
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- 呼叫运营商<<临时
- 如何防止clang格式在流运算符调用之间添加换行符<<
- <<操作员在下面的行中工作
- EASTL矢量<向量<int>>连续的
- C - 创建矢量&lt; vector&lt; double&gt;&gt;矩阵具有分配而不是inizializ
- 为什么将此对向量&lt; map&lt; int,int&gt;&gt;中的地图进行更新.失败
- C :对矢量进行排序&lt; struct&gt;(结构有2个整数)基于结构的整数之一
- 明确的专业化“ CheckIntmap&lt;&gt;”实例化
- 什么是模板&lt;&gt;inline bla bla
- 编辑C Qlist&lt; object*&gt; gt;QML代码和一些QML警告中的模型
- eigen :: llt&lt;eigen :: matrixxd&gt;具有不完整的类型
- 错误,包括&lt; ctype&gt;在原子上使用C 11
- std::vector<;uint8_t>;当C++11/14启用时,手动复制而不是调用memcpy
- 如何加入向量&lt; int&gt;到C 中的单个INT
- 是std :: set&lt; std :: future&gt;不可能存在
- 是numeric_limits&lt; int&gt; :: is_modulo从逻辑上矛盾
- opencv 2.4.7在iOS错误背景_segm.hpp #include&lt; list&gt;未找到
- 在修改列表后,std :: list&lt; t&gt; :: end()的值是否会更改
- ///<评论></评论>在Visual Studio中