So I'm making a script to make a txt file and put data on it, but when I run the system(); function, I get a strange error. Here's the code.
#include <iostream>
#include <fstream>
#include <stdlib.h>
using namespace std;
int main()
{
string textFileName = "SavedPasswords.txt";
string currentPassword = "Pas123!()";
string currentName = "Home";
string seperator = "====================";
ofstream textFile(textFileName.c_str());
textFile << "N: " << currentName << endl << "P: " << currentPassword << endl << endl << seperator << endl;
string directory;
size_t path = textFileName.rfind("\\");
if(string::npos != path)
{
directory = textFileName.substr(0, path);
}
string systemCommands[3] = {"cd\\",
"cd " + directory,
"start " + textFileName};
system(systemCommands[0]);
system(systemCommands[1]);
system(systemCommands[2]);
}
C:\Users\User\Desktop\SavePasswords\main.cpp|29|error: cannot convert 'std::string {aka std::basic_string}' to 'const char*' for argument '1' to 'int system(const char*)'|
I get the same error for the next two lines.