该代码应该创建一个txt文档并在其中放置一些文本。但是,在第10,25和26行(我将在旁边发表评论),我收到了错误。请帮助,并提前致谢!创建txt文档C++
#include <iostream>
#include <fstream>
#include <stdlib.h>
using namespace std;
int main()
{
string textFileName = "SavedPasswords.txt";
ofstream textFile(textFileName);//10
textFile << "Password1" << endl << "Password2" << endl;
textFile.close();
string directory;
size_t path = textFileName.rfind("\\");
if(string::npos != path)
{
directory = textFileName.substr(0, path);
}
system("cd\\");
system("cd " + directory);//25
system("start " + textFileName);//26
}
下面是错误:
C:\Users\User\Desktop\SavePasswords\main.cpp|10|error: no matching function for call to 'std::basic_ofstream::basic_ofstream(std::string&)'|
C:\Users\User\Desktop\SavePasswords\main.cpp|25|error: cannot convert 'std::basic_string' to 'const char*' for argument '1' to 'int system(const char*)'|
C:\Users\User\Desktop\SavePasswords\main.cpp|26|error: cannot convert 'std::basic_string' to 'const char*' for argument '1' to 'int system(const char*)'|
编译器错误?你收到什么错误?如果你将其添加到你的问题,这将有所帮助。 – Tas
在下面发布了错误。 – onlineone22
什么是10,25和26行? –