Задача: вызвать функцию fc (сравнение двух файлов) из C++. В идеале: system("fc file1 file2"). Имеется: Code: #include <string> #include <atlstr.h> ... CString srcFile = "infile.txt"; CString decFile = "decrypted.txt"; ... if (system("fc " + srcFile + " " + decFile) == 0) { cout << "Files " << srcFile << " and " << decFile << " are identical." << endl; } Ошибка: Code: error C2664: 'system' : cannot convert parameter 1 from 'ATL::CStringT<BaseType,StringTraits>' to 'const char *' Я уверен, что решение очень простое, я просто очень давно не использовал C++, так что сильно не ругайте
Code: #include "iostream" int main(int argc, char* argv[]) { int i = system("fc 1.txt 3.txt"); if(i==0) printf("The different"); else if(i==1) printf("The different"); else printf("Error"); return 0; } ну а если ты имена файлов передавать как параметры, то memset, strcpy тебе в помощь, так как в ф-ции system char* =)
Спасибо за помощь Я вот так вот решил: Code: #include <string> ... string srcFile = "infile.txt"; string decFile = "decrypted.txt"; string cmd; ... cmd = "fc " + srcFile + " " + decFile; if (system(cmd.c_str()) == 0) { cout << "-> Files " << srcFile << " and " << decFile << " are identical." << endl; } ...