ошибка getline()

Я пишу эту функцию, которая копирует содержимое одного файла в другой. Я использую функцию 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' (или нет приемлемого преобразования)"


person GKED    schedule 12.07.2011    source источник
comment
Не заставляйте нас угадывать ошибку компилятора   -  person antlersoft    schedule 13.07.2011
comment
Какова точная ошибка компилятора и в какой строке?   -  person Nobody moving away from SE    schedule 13.07.2011
comment
Какая ошибка и какая строка кода? Я попробовал это с ideone, и, похоже, он отлично компилируется: ideone.com/BO7tY   -  person Tony The Lion    schedule 13.07.2011


Ответы (1)


Одна из проблем заключается в том, что вы не включили заголовочный файл <string>, в котором определяется getline.

person John Harrison    schedule 12.07.2011