Я все время получаю ошибку «отсутствие соответствия» при компиляции этого кода. Может ли кто-нибудь помочь мне с этим?Выходной файл выпуск в C++
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <string>
using namespace std;
int main()
{
string filename[]="Hello.txt";
ofstream OutFile;
OutFile.open(filename);
if(OutFile.fail()) // check for successfully open ,
{
cout << "file named can not be found \n";
exit(1);
}
OutFile << "Hello, this is my output file";
OutFile.close();
system("pause");
return 0;
}
EDIT: А что при чтении и displaing файл? У меня проблемы с getline, и он не будет компилироваться. Может ли кто-нибудь указать на проблему?
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <string>
using namespace std;
int main()
{
char filename[] = "Hello.txt";
string line = "Hello, this is my output file";
ofstream OutFile;
OutFile.open(filename);
if(OutFile.fail()) // check for successfully open ,
{
cout << "file named can not be found \n";
exit(1);
}
OutFile << line;
if (OutFile.is_open())
OutFile.getline(line);
OutFile.close();
system("pause");
}
Это единственный аргумент (единственный строковый аргумент) - OutFile.open (имя файла). Вы используете массив имен файлов. Ваша трассировка стека ошибок должна показать вам. Вместо этого используйте одну строку. – ha9u63ar
И, пожалуйста, в следующий раз, когда вы получите сообщение об ошибке, сообщите нам, в какой строке возникает ошибка, и какой компилятор вы используете. –