#include <iostream.h>
#include <string>
using namespace std;
int main()
{
string best_name=" ";
double best_price=1;
int best_score=0;
bool more=true;
while (more)
{
string next_name;
double next_price;
int next_score;
cout<<"please enter the model'name:"<<endl;
getline (cin,next_name);
cout<<"please enter the price:"<<endl;
cin>>next_price;
cout<<"please enter the score:"<<endl;
cin>>next_score;
string remainder;
getline(cin,remainder);
if (next_scor/next_price>best_score/best_price)
{
best_name=next_name;
best_price=next_price;
best_score=next_score;
}
cout<<"do you want to continue?(y/n)"<<endl;
string answer;
getline(cin,answer);
if (answer!="y")
{
more=false;
}
cout<<"the best value is"<<best_name
<<"price:"<<best_price
<<"score:"<<best_score<<endl;
}
return 0;
}
错误提示如下:
--------------------Configuration: bestval - Win32 Debug--------------------
Compiling...
bestval.cpp
e:\vc++\add\bestval\bestval.cpp(20) : error C2780: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &,const _E)' : expects 3 arguments - 2 provided
d:\编程语言\vc98\include\string(149) : see declaration of 'getline'
e:\vc++\add\bestval\bestval.cpp(20) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &)' : could not deduce template argument for 'class std::basic_istream<_
E,_Tr> &' from 'class istream_withassign'
e:\vc++\add\bestval\bestval.cpp(20) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &)' : could not deduce template argument for 'class std::basic_istream<_
E,_Tr> &' from 'class istream_withassign'
e:\vc++\add\bestval\bestval.cpp(20) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &)' : could not deduce template argument for 'class std::basic_istream<_
E,_Tr> &' from 'class istream_withassign'
e:\vc++\add\bestval\bestval.cpp(26) : error C2780: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &,const _E)' : expects 3 arguments - 2 provided
d:\编程语言\vc98\include\string(149) : see declaration of 'getline'
e:\vc++\add\bestval\bestval.cpp(26) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &)' : could not deduce template argument for 'class std::basic_istream<_
E,_Tr> &' from 'class istream_withassign'
e:\vc++\add\bestval\bestval.cpp(26) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &)' : could not deduce template argument for 'class std::basic_istream<_
E,_Tr> &' from 'class istream_withassign'
e:\vc++\add\bestval\bestval.cpp(26) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &)' : could not deduce template argument for 'class std::basic_istream<_
E,_Tr> &' from 'class istream_withassign'
e:\vc++\add\bestval\bestval.cpp(27) : error C2065: 'next_scor' : undeclared identifier
e:\vc++\add\bestval\bestval.cpp(36) : error C2780: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &,const _E)' : expects 3 arguments - 2 provided
d:\编程语言\vc98\include\string(149) : see declaration of 'getline'
e:\vc++\add\bestval\bestval.cpp(36) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &)' : could not deduce template argument for 'class std::basic_istream<_
E,_Tr> &' from 'class istream_withassign'
e:\vc++\add\bestval\bestval.cpp(36) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &)' : could not deduce template argument for 'class std::basic_istream<_
E,_Tr> &' from 'class istream_withassign'
e:\vc++\add\bestval\bestval.cpp(36) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &)' : could not deduce template argument for 'class std::basic_istream<_
E,_Tr> &' from 'class istream_withassign'
e:\vc++\add\bestval\bestval.cpp(43) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conver
sion)
执行 cl.exe 时出错.
bestval.exe - 1 error(s), 0 warning(s)