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();
}
对于cin错误: error C2678: binary '>>' : 没有找到接受类型为 'std::istream' 的左手操作数的运算符(或者没有可接受的转换)
对于 strnicmp 错误: 错误 C2664:“strlen”:无法将参数 1 从“std::string”转换为“const char *”
我已搜索过此问题的解决方案,但无法解决。如果这里有类似的帖子可以解决我的问题,我深表歉意。
最佳答案
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)
添加#include <string>
到您的 CPP 文件。
For the strnicmp error: error C2664: 'strlen' : cannot convert parameter 1 from 'std::string' to 'const char *'
确认您有 #include <cstring>
到您的 CPP 文件,并将您的调用替换为:
strnicmp(airport.c_str(), flights[r].airport[20], strlen(airport.c_str()) ==0
.
我怀疑flights[r].airport[20]
也是不正确的,但我不知道,因为你没有发布完整的程序。
如果cust::airport
声明为 std::string airport;
, 那么你需要 flights[r].airport.c_str()
.
如果cust::airport
声明为 char airport[20];
, 那么你需要 flights[r].airport
.
关于C++ cin 和 strnicmp 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10192483/