| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 601 人关注过本帖
标题:[求助]程序提示错误看不懂
只看楼主 加入收藏
taijixing
Rank: 1
等 级:新手上路
威 望:1
帖 子:118
专家分:0
注 册:2007-6-9
收藏
 问题点数:0 回复次数:4 
[求助]程序提示错误看不懂

#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)

搜索更多相关主题的帖子: 提示 
2007-07-25 15:39
taijixing
Rank: 1
等 级:新手上路
威 望:1
帖 子:118
专家分:0
注 册:2007-6-9
收藏
得分:0 
以上程序想实现一个最佳性价比的 功能
请大侠帮忙看看!
2007-07-25 15:40
taijixing
Rank: 1
等 级:新手上路
威 望:1
帖 子:118
专家分:0
注 册:2007-6-9
收藏
得分:0 
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)
想这种错误经常出现
不知道原因
2007-07-25 15:41
gxslkz
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2007-7-25
收藏
得分:0 

#include "stdafx.h"
#include <iostream>
#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_score/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;
}

上面是修改的.可以通过编绎.

你的问题主要:
第一:#include <iostream.h> 这里用了using namespace std; 这里的.h就不要用了
即 <iostream.h> 修改为<iostream>

第二:if (next_scor/next_price>best_score/best_price)
这里的next_scor错误,应该是next_score

2007-07-25 23:23
taijixing
Rank: 1
等 级:新手上路
威 望:1
帖 子:118
专家分:0
注 册:2007-6-9
收藏
得分:0 
非常感谢
向你敬礼
2007-07-26 00:13
快速回复:[求助]程序提示错误看不懂
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016843 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved