該代碼應該創建一個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行? –