2014-11-28 1 views
-2

저는 C++을 처음 사용합니다. 두 개의 .txt 파일이 있습니다. 하나는 다른 .txt 파일에서 찾길 원하는 3 가지 키워드입니다. 마녀는 긴 문자입니다. 두 파일을지도에 삽입하려고하는데 어떻게해야할지 모르겠다.지도에 파일을 삽입하십시오.

나는 이것을 시도했다 num.insert(pair<string,string>(clef,index)); 그러나 그것은 효과가 없다. 도와주세요.

#include <iostream> 
#include <fstream> 
#include <string> 
#include <map> 
#include <iterator> 

using namespace std; 


ofstream index("index.txt", ios::out | ios::app); 


int main() 
{ 
    map <string, string> num; 
    map <string,string> ::iterator it; 
    int ctrLigne = 1; 
    int ctrPage=1; 
    int ctr=1; 


    ifstream docum ("docum.txt", ios::in); 
    ifstream clef ("clef.txt", ios::in); 

    /* what I have tried but did not work 
     while (docum >> clef >> index){ 
      num[clef] = index; 
     } 



    num.insert(pair<string,string>(clef,index)); 
    num.insert(clef, index); 
    */ 



    if (docum) 
    { 
     string ligne; 

     while(getline(docum, ligne)) 
     { 
      cout << ligne << " Ligne : " << ctrLigne << " Page : " << ctrPage << endl; 

      if(ctr==4) 
      { 
       ctr=0; 
       ctrPage++; 
      } 

      ctrLigne++; 

      ctr++; 
    } 


    docum.close(); 
    clef.close(); 


    system("pause"); 
    return 0; 
    } 
+2

"작동하지 않음" –

+2

이 문제에 필수적인 전체 코드를 게시하십시오. . – Ari0nhh

답변

0

당신은 간단한지도와 함께 할 긴 문자열로 파일의 내용을 저장할 수 있습니다 : Ari0nhh @ 사전 :

에서

덕분에이 모든 내 코드입니다.

#include <iostream> 
#include <map> 
#include <string> 
using namespace std; 

int main() { 
    // your code goes here 
    string fileName="myFile.txt"; 
    string myFilecontent="All The secrets of the world\n Line 1\n Line2";//includes line breaks 
    map<string,string> fileMap; 
    fileMap[fileName]=myFilecontent; 
    cout<<fileMap[fileName]; 
    return 0; 
} 

OUPUT : 도움이 세계

1 호선

라인 2

희망의

모든 비밀, 당신은 주위에 많은 컨텍스트를 필요 해요