2012-05-09 6 views
1

C++에서 getline()을 사용하여 어떤 헤더를 사용할지 알려주실 수 있습니까? 내가 사용했습니다getline 함수가 작동하지 않습니다.

#include<iostream> 
#include<string> 
#include<stdio.h> 
#include<stdlib.h> 
using namespace std; 

아무도 작동하지 않는 것 같습니다.

는 여기에 당신이 사용하고있는 버전의 경우 지금까지

#include "stdafx.h" 
#include<iostream> 
#include<string> 
#include<vector> 
#include<set> 
#include<map> 
using namespace std; 

class TextQuery 
{ 
    typedef map<string, set<string::size_type> > word_map; 
    TextQuery(ifstream &file) 
    { 
     FillLineVector(file); 
     BuildMap(file); 
    } 

    void query(string); 
private: 
    word_map map; 
    vector<string> LineVector; 
    void FillLineVector(const ifstream&); 
    void BuildMap(const ifstream&); 
}; 

void TextQuery::FillLineVector(const ifstream& file) 
{ 
    string line; 
    while(getline(file,line)); //error:getline identifier not found 
} 
+0

"작동하지 않음"이란 무엇을 의미합니까? 제발 좀 더 구체적으로. – suszterpatt

+0

getline을 사용하여 질문에 코드를 추가하십시오. –

+0

게시물을 편집하면 – user1232138

답변

2

당신은 iostream 가능성이 string 필요 내가 작성한 전체 코드입니다. 추가 정보를 제공하지 않아서 작동하지 않는 이유는 신비로 남아 있어야합니다.

+0

코드가 포함되어 있습니다. 뭐가 잘못 되었습니까? – user1232138

2

사람들이 나를 도와 줄 수 있도록 코드를 게시하십시오. 어쨌든,의 getline이 같은 표기 :

// getline with strings 
#include <iostream> 
#include <string> 
using namespace std; 

int main() { 
    string str; 
    cout << "Please enter full name: "; 
    getline (cin,str); 
    cout << "Thank you, " << str << ".\n"; 
} 

바와 같이 http://www.cplusplus.com/reference/string/getline/

+0

코드가 포함되어 있습니다. 문제를 찾을 수 있습니까? – user1232138

1

에서 보여 귀하의 기능 ifstream보다는 istream 가지고, 그래서 당신은 그 정의를 얻을 수 <fstream>을 포함해야합니다.

그러나 어쨌든 파일로만 작업 할 수있는 경우가 아니면 istream을 사용하여 기능을보다 일반화하는 것이 좋습니다. 이 경우 이미 가지고있는 <iostream><string> 만 있으면됩니다.

관련 문제