C++ 删除包含单词的行

C++ 删除包含单词的行,c++,C++,我试图从文本文件中删除包含特定单词的行 但它不起作用 void deleteline() { string line, deletecontact; cout << "Plase enter the contact (name or number) to delete:"; cin >> deletecontact; ifstream file; ofstream outfile; file.open("data.txt")

我试图从文本文件中删除包含特定单词的行 但它不起作用

void deleteline()
{
    string line, deletecontact;
    cout << "Plase enter the contact (name or number) to delete:";
    cin >> deletecontact;
    ifstream file;
    ofstream outfile;
    file.open("data.txt");
    outfile.open("newM.txt");
    while (getline(file, line)) {
        if (line != deletecontact) {
            outfile << line << endl;
        }
    }
    outfile.close();
    file.close();
    remove("movieList.txt");
    rename("newM.txt", "data.txt");
}
void deleteline()
{
弦线,删除触点;
cout>deletepact;
ifstream文件;
出流孔的直径;
打开(“data.txt”);
outfile.open(“newM.txt”);
while(getline(文件,行)){
如果(行!=deletecontact){

outfile仅当行数相等时(即
line!=deleteContact
)才能删除行数。如果要删除如您所述仅包含此单词的行数,应编写如下内容:

if(strstrstr(line.c_str(),deleteContact.c_str())==nullptr)。。。

仅当行数相等时(即
行!=deleteContact
)才能删除行数。如果要删除如您所述仅包含此单词的行数,应编写如下内容:

if(strstrstr(line.c_str(),deleteContact.c_str())==nullptr)。。。

另请参见std::string::find使用
std::search
进行不区分大小写的搜索。
strstr
更像是一个“C”函数。您是否使用了调试器并查看了
line
delete contact
?可能是编码问题……很抱歉,这是我的错,我正在检查其他文件请参见std::string::find>使用
std::search
进行不区分大小写的搜索。
strstr
更像是一个“C”函数。您是否使用了调试器并查看了
line
deletecontact
?可能是编码问题……很抱歉,它起作用了,是我的错,我检查了其他文件?
删除(“movieList.txt”)
不应该是
删除(“data.txt”);
删除(“movieList.txt”);
不应该是
删除(“data.txt”);