2012-04-17 11 views
0
void searchFlight(cust flights[] ,int row) 
{  
    clrscr(); 
    cout << "Search for the flight you are looking for.\n"; 

    string airport; 

    cout << "Enter Departing Flight : "; 
    cin >> airport; //error 

    for (int r=0;r<row;r++) 
    { 
     if (strnicmp(airport, flights[r].airport[20], strlen(airport) ==0) //error 
     { 
      clrscr(); 
      cout << flights[r].name[20] <<endl; 
      cout << flights[r].airport[20] <<endl; 
      cout << flights[r].destination[20] <<endl; 
      cout << flights[r].ticket <<endl; 
      cout << flights[r].passangers <<endl; 
      cout << flights[r].opCost <<endl; 
      cout << flights[r].income <<endl; 
      cout << flights[r].netProfit <<endl;; 
      pressKey(); 
     } 
    } 
    pressKey(); 
} 

作業ないstrnicmp: エラーC2678:バイナリ「>>」:なしオペレータはタイプの左オペランドとる見つかりません「STDを::のIStream」(または全く存在し エラーC2664:「strlenを」:strnicmpエラーのために許容可能な変換)C++ CINおよびCINエラーの

私はこの問題の解決策を検索しました

「のconstのchar *」から「のstd ::文字列」からパラメータ1を変換することはできませんし、それを修正することができませんでした。私の問題を解決したかもしれない同様の記事がここにある場合は謝罪してください。

<fstream> 
<istream> 
<iostream> 
<string> 

私はあなたがここで<string>

を忘れてしまった私は走ったテストコードだと、それは完璧に働いていたかなり確信している:

+0

""を含めていますか? – karlphillip

+2

std :: stringの長さを見つけるには 'std :: string :: length()'を使う必要があります。また、ヘッダが含まれているかどうかを確認してください。。 – Mahesh

+0

これはちょうど昨日尋ねられました.. http://stackoverflow.com/questions/10183008/cin-has-no-operand/10183049#10183049 –

答えて

1

For the cin error: error C2678: binary '>>' : no operator found which takes a left-hand operand of type 'std::istream' (or there is no acceptable conversion)

あなたのCPPファイルに#include <string>を追加します。 strnicmp(airport.c_str(), flights[r].airport[20], strlen(airport.c_str()) ==0:あなたのCPPファイルに#include <cstring>を持っている、として、あなたの呼び出しを置き換える

For the strnicmp error: error C2664: 'strlen' : cannot convert parameter 1 from 'std::string' to 'const char *'

ことを確認します。

flights[r].airport[20]も間違っていると思われますが、完全なプログラムを投稿していないためわかりません。

cust::airportstd::string airport;のように宣言されている場合は、flights[r].airport.c_str()が必要です。

char airport[20];のように宣言された場合、flights[r].airportが必要です。

+0

お返事ありがとうございます! #include が動作します。私は、 'namespace stdを使用すること'が私が必要としていたすべての印象を受けました。 – user1338894

+0

私はあなたが言ったことをやりました。新しいエラーが発生しました。パラメータ2を 'char'から 'const char *'に変換できません。 – user1338894

+0

最新の編集を参照してください。あなたは 'フライト[r] .airport'、** not **' flights [r] .airport [20] 'と言う必要があります。最初のものは配列の名前です。もう1つは配列の21番目の文字です。 –

1

では、次の含まれています!

#include <string> 
#include <iostream> 

using namespace std; 

int main(int, char**) 
{ 
    string foo; 
    cin >> foo; 
    cout << foo; 
}