Я пытаюсь создать файл output.txt из файла .py python в c ++.
Я пытаюсь: - скопировать код из python в вектор - создать файл outputText - открыть этот файл outputText - прочитать файл outputText (с кодом python), но у меня возникают проблемы ( пожалуйста посмотрите код)
using namespace std;
int main(int argc, char** argv) {
string fileName = argv[1];
vector<string> pythonData;
ifstream pythonFile(fileName);
string linePython;
while (getline(pythonFile, linePython)) {
pythonData.push_back(linePython);
}
pythonFile.close();
cout << fileName << endl;
for (unsigned int i = 0; i < pythonData.size(); i++) {
cout << pythonData[i] << endl;
}
string pythonFileName = "pythonCode.txt";
ofstream pythonCode(pythonFileName.c_str());
if (pythonCode.is_open()) {
// cout << "outputfile inshallah\n";
for (int i = 0; i < pythonData.size(); i++) {
pythonCode << pythonData[i].c_str() << "\n";
}
}
pythonCode.close();
/// UP UNTIL THIS POINT I WAS FINE...
// BUT TROUBLE COMES IN WITH CODE BELOW
ifstream readFile(pythonFileName);
string line;
int i = 0;
if (readFile.is_open()) {
while (getline(readFile, line)) {
cout << line << endl;
cout << i++ << endl; // processes( call functions..)
}
}
}
Буду очень признателен за любые решения! Надеюсь, это ясно. Также предположим, что я включил все заголовочные файлы