2017-03-01 7 views
-1

とのgetlineを使用して、私が過負荷にオペレータと機能at()stringの独自のクラスを作成します。私は別のクラスでそれを埋め込むためにそれを作成しました。私は1つを除いて何の問題もない。申し訳ありませんが自分のクラスC++

私のエラーは、次のとおりです。

std::basic_istream<_Elem,_Traits>&std::getline(std::basic_istream<_Elem,_Traits>&,std::basic_string<_Elem,_Traits,_Alloc> &)': could not deduce template argument for 'std::basic_string<_Elem,_Traits,_Alloc> &' from 'String' 

問題がgetline()機能です。この機能は、私がMY stringを使用して、私のファイルを読み込むためのgetline()に別近いバリアントを見つけ引数str .CanとしてMY stringを取ることはありませんか?

なぜMY文字列でgetline()仕事、なぜそれがいくつかの実際の文字列を待たないことができませんか?

My機能は次のとおりです。

void City::readRecordings(char *fileName, char *num, std::vector<string> lines) 
{ 

    string str; 
    //std::ifstream fin(fileName); 
    readRecord >>str; 
    int readCount = 0; 
    int n = atoi(num); 
    readRecord.open(fileName); 
    while (!readRecord.eof()) 
    { 
     std::getline(readRecord, str);/*here is Error, It can't use my String str , it waits for usual string*/ 
     readCount++; 
     lines.push_back(str); 
    } 

    if (0 == readCount) 
    { 
     std::cout << "ERROR: The file, which you are trying to open, is empty or it stops out" << end; 
     exit(-1); 
    } 
    if (n > readCount) 
    { 
     std::cout << "!Warning!" << end; 
     std::cout << "You want to read " << n << " recordings" << " But AVAILABLE: " << readCount << " recordings" << end; 
     printRecordsFromFile(readCount, lines); 
    } 
    else 
    { 
     printRecordsFromFile(n, lines); 
    } 
} 
+0

それは空が青いのと同じ理由です: 'のstd :: getlineの()'の2番目のパラメータは 'のstd :: STRING'あるので(まあ、'のstd :: basic_string'は、知識をひけらかすこと)。それはどのような 'のstd :: getlineの()'であるのです。 –

+0

だから_fromだ何String'_はエラーメッセージで述べました。あなた自身のもの? –

+0

@πάνταῥεῖはい、私は私の文字列のために実現しました –

答えて

0

あなたの文字列クラスを使用して、独自のgetline関数を記述するために歓迎されている:

std::istream& 
std::getline(std::istream& input_stream, My_String& s, char delimiter = '\n') 
{ 
    //... 
    return input_stream; 
} 

std::stringを使用しての代わりに、独自の文字列を開発するには多くの利点があります。クラス。

関連する問題