C++ 文本文件行删除
在这个函数中,我能够将值从文件传递到链接列表,但删除文本文件中传递的值行时遇到问题。线路替换功能不知怎么地不起作用。我不知道如何解决这个问题C++ 文本文件行删除,c++,C++,在这个函数中,我能够将值从文件传递到链接列表,但删除文本文件中传递的值行时遇到问题。线路替换功能不知怎么地不起作用。我不知道如何解决这个问题 void data::returndata(int code) { string title; string genre; string production; string temp; fstream myfile; myfile.open("
void data::returndata(int code)
{
string title;
string genre;
string production;
string temp;
fstream myfile;
myfile.open("data.txt");
string line;
string token = to_string(code);
while (getline(myfile, line))
{
int cnt = 0;
if (line.find(token) != string::npos) {
cout << line << endl;
for (int x = 0; x < line.length(); x++) {
if (line[x] == '|' || line[x] == ']') {
if (cnt == 0) {
code = atoi(temp.c_str());
temp = "";
}
else if (cnt == 1) {
title = temp;
temp = "";
}
else if (cnt == 2) {
genre = temp;
temp = "";
}
else if (cnt == 3) {
production = atoi(temp.c_str());
temp = "";
}
cnt++;
}
else if (line[x] == '[') {
temp = "";
continue;
}
else {
temp = temp + line[x];
}
}
line.replace(line.find(token), token.length(), " ");
insertNode(code, title, genre, production);
}
}
}
void数据::returndata(int代码)
{
字符串标题;
弦乐体裁;
管柱生产;
字符串温度;
fstream-myfile;
myfile.open(“data.txt”);
弦线;
字符串标记=到字符串(代码);
while(getline(myfile,line))
{
int-cnt=0;
if(line.find(token)!=string::npos){
你不能删除一行。你可以重写文件。