【发布时间】:2021-05-03 08:56:04
【问题描述】:
我想删除密码为小写字母的txt文件。
创建文件代码:
FILE *files[20];
char filename[20];
sprintf(filename, "%d.txt", i);
files[i] = fopen(filename, "w");
string login, pass;
//wprowadzanie zmian w licznie kont
fstream liczb;
liczb.open("liczbakont.txt", ios::out);
liczb<<i;
//tworzenie plików dla poszczególnych kont
fstream plik(to_string(i)+".txt");
plik<<"\n";
cout<<"Podaj login: "<<endl;
删除:
cout<<"pass: "<<endl;
cin>>pass;
if(islower (haslo[0]) )
{
if( remove(to_string(i)+".txt") == 0)
}
怎么了?
[错误] 无法将参数 '1' 的 'std::basic_string' 转换为 'const char*' 到 'int remove(const char*)' [错误] '}' 标记之前的预期主表达式 [错误] '}' 标记之前的预期声明
【问题讨论】:
-
remove想要一个 c 字符串 (const char *) 而不是std::string。但是to_string()返回一个std::string。您可以使用std::string::c_str()函数从std::string获取 c 字符串。 -
如果您查看错误消息,它说
remove的参数必须是const char *。这是因为remove确实是一个C函数,它对std::string这样的C++对象一无所知。 -
@JohnnyMopp 那么我需要更改或添加什么?
标签: c++