Я пишу эту функцию, которая копирует содержимое одного файла в другой. Я использую функцию getline() в цикле while. Почему-то компилятор выдает мне ошибку. Ты знаешь почему? Вот мой код:
#include<iostream>
#include<cstdlib>
#include <fstream>
using namespace std;
// Associate stream objects with external file names
#define inFile "InData.txt" // directory name for file we copy from
#define outFile "OutData.txt" // directory name for file we copy to
int main(){
int lineCount;
string line;
ifstream ins; // initialize input object an object
ofstream outs; // initialize output object
// open input and output file else, exit with error
ins.open("inFile.txt");
if(ins.fail()){
cerr << "*** ERROR: Cannot open file " << inFile
<< " for input."<<endl;
return EXIT_FAILURE; // failure return
}
outs.open("outFile.txt");
if(outs.fail()){
cerr << "*** ERROR: Cannot open file " << outFile
<< " for input."<<endl;
return EXIT_FAILURE; // failure return
}
// copy everything fron inData to outData
lineCount=0;
getline(ins,line);
while(line.length() !=0){
lineCount++;
outs<<line<<endl;
getline(ins,line);
}
// display th emessages on the screen
cout<<"Input file copied to output file."<<endl;
cout<<lineCount<<"lines copied."<<endl;
ins.close();
outs.close();
cin.get();
return 0;
}
Спасибо за помощь.
РЕДАКТИРОВАТЬ: извините, вот ошибки: 1. "ошибка C3861: 'getline': идентификатор не найден" 2. "ошибка C2679: двоичный '‹‹': не найден оператор, который принимает правый операнд типа 'std: :string' (или нет приемлемого преобразования)"