64,662
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <sstream>
#include <fstream>
using namespace std;
void write_in_text(const string &str)
{
int num1, num2; char ch;
string textline;
istringstream message_stream(str);
message_stream >> num1;
fstream in_outfile;
in_outfile.open("11.txt", fstream::in | fstream::out | fstream::binary);
while(getline(in_outfile, textline))
{
message_stream.str(textline);
message_stream >> num2;
if(num1 == num2)
{
cout << "编号\'" << num1
<< "\'已存在, 是否要覆盖?(Y/N)"
<< endl;
if((ch = cin.get()) == 'Y' || ch == 'y')
{
cout << str;
in_outfile << str;
in_outfile.close();
}
return;
}
else if(num1 < num2+1)
{
in_outfile << str;
in_outfile.close();
return;
}
}
in_outfile << str;
in_outfile.close();
}
int main()
{
int num;
string str = "3 asdkjfkgf";
write_in_text(str);
return 0;
}