gpt4 book ai didi

c++ - 过滤 getline 收到的输入

转载 作者:行者123 更新时间:2023-11-28 07:44:30 24 4
gpt4 key购买 nike

<分区>

#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
using namespace std;

int main() {

string firstFile, secondFile, temp;

ifstream inFile;
ofstream outFile;

cout << "Enter the name of the input file" << endl;
cin >> firstFile;

cout << "Enter the name of the output file" << endl;
cin >> secondFile;

inFile.open(firstFile.c_str());
outFile.open(secondFile.c_str());

while(inFile.good()) {

getline(inFile, temp, ' ');

if ( temp.substr(0,4) != "-----"
&& temp.substr(0,5) != "HEADER"
&& temp.substr(0,5) != "SUBID#"
&& temp.substr(0,5) != "REPORT"
&& temp.substr(0,3) != "DATE"
&& temp != ""
&& temp != "")
{
outFile << temp;
}
}

inFile.close();
outFile.close();

return 0;
}

大家好。我试图从一个文本文件中输出所有不符合控制结构标准的行——即没有空行、没有符号等。但是,当我运行这段代码时,它输出了所有内容,没有考虑我的具体要求。如果有人能告诉我我做错了什么,将不胜感激。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com