| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1332 人关注过本帖
标题:程序运行总是出错,不知道为什么,请教各位帮忙
只看楼主 加入收藏
abraham1990
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2011-1-10
结帖率:50%
收藏
已结贴  问题点数:10 回复次数:15 
程序运行总是出错,不知道为什么,请教各位帮忙
//getinfo.cpp--input and output
#include<iostream>
int main()
{
    using namespace std;
    int carrots;
    cout<<"how many carrots do you have?"<<endl;
    cin>>carrots;       //c++input
    cout<< "here are two more.";
    carrots=carrots+2;
    //the next line concatenates output
    cout<<"now you have"<<carrots<<"carrots."<<endl;
    return 0;

}
这是我按书上编的一个程序,应该是不会错的,请各位大侠帮忙看看,我用的是microsoft visual studio 2008 .net的版本

首先有个问题,为什么每次生成的程序总是被VS显示为已经过时了,这是什么情况

运行之后显示有两个错误,不知道是什么错误。。。谁能帮忙
我是刚入门的那种,对C++的了解很浅,谢谢帮助哈!!!
搜索更多相关主题的帖子: microsoft 
2011-01-10 09:53
li_danwang
Rank: 4
来 自:鄂州
等 级:业余侠客
帖 子:112
专家分:203
注 册:2010-11-12
收藏
得分:1 
VC6.0  运行正常   哈哈.

没事来C一下...   
2011-01-10 10:21
qq1023569223
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:湖南科技大学
等 级:贵宾
威 望:26
帖 子:2753
专家分:13404
注 册:2010-12-22
收藏
得分:1 
#include<iostream>
using namespace std;  //你怎么把这句写在main()里面去了?
int main()
{
     int carrots;
    cout<<"how many carrots do you have?"<<endl;
    cin>>carrots;       //c++input
    cout<< "here are two more.";
    carrots=carrots+2;
    //the next line concatenates output
    cout<<"now you have"<<carrots<<"carrots."<<endl;
    return 0;
}
可能是过时了吧。 新出来的吗?好东西啊。我的2003的老是装不上


   唯实惟新 至诚致志
2011-01-10 21:38
xueshui20
Rank: 5Rank: 5
等 级:职业侠客
威 望:1
帖 子:269
专家分:309
注 册:2009-4-19
收藏
得分:1 
命名空间using namespace std;放错位置了
2011-01-10 23:56
找工作中
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:41
专家分:114
注 册:2008-5-21
收藏
得分:1 
1. using namespace std;没有放错位置,这两个位置都可以的
2. 即使是using namespace std;放错位置导致的错误,应该也是编译错误,而不是运行错误
3. 这段程序虽然写得不好,但是应该不会有运行错误。如果有错误的话,lz至少应该说出是什么错误(错误总有信息/对话框之类的吧,否则你凭什么说出错了呢)。

拿到工资先买个山寨手机
2011-01-11 07:22
xdzsm
Rank: 2
等 级:论坛游民
帖 子:137
专家分:99
注 册:2010-10-26
收藏
得分:1 
C-Free 下正常!显示  how many carrots do you have?
2011-01-11 14:27
abraham1990
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2011-1-10
收藏
得分:0 
我试过很多方法。。。。
很多朋友帮忙看过了。。。。。。
最终是这样的程序。。。。



#include<iostream>
#include<string>
int main()
{
     using namespace std;
     char name[20];
     char address[20];
     cout<<"please input your name"<<endl;
     gets(name);
     cout<<"please input your address"<<endl;
     gets(address);
     cout<<"your name is "<<name<<endl;
     cout<<"your address is"<<address<<endl;
     return 0;
}
帮忙解释一下先。。。。看不懂。。。。char和gets()一般有什么用。。。。
c:\documents and settings\administrator\my documents\visual studio 2008\projects\24asfsaf\24asfsaf\erfa.cpp(11) : error C2679: 二进制“>>”: 没有找到接受“std::string”类型的右操作数的运算符(或没有可接受的转换)
运行时候会看到这个。。。一直是这样。。。。总是会出现这个。。。。
请问这是什么情况???
2011-01-11 23:03
abraham1990
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2011-1-10
收藏
得分:0 
还有朋友这样帮忙解决的:
//my first.cpp
#include<iostream>
#include<string>
int main()
{
    using namespace std;
    string name ;
    string address;
    cout<<"please input your name"<<endl;
    cin>>name;
    cout<<"please input your sddress"<<endl;
    cin>>address;
    cout<<"your name is "<<name<<endl;
    cout<<"your address is"<<address<<endl;
    return 0;
}
c:\documents and settings\administrator\my documents\visual studio 2008\projects\24asfsaf\24asfsaf\erfa.cpp(11) : error C2679: 二进制“>>”: 没有找到接受“std::string”类型的右操作数的运算符(或没有可接受的转换)
谢谢各位热心帮忙看看
2011-01-11 23:07
abraham1990
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2011-1-10
收藏
得分:0 

#include<string>
int main()
{
     using namespace std;
     string name1,name2;
     string address1,address2;
     cout<<"please input your name"<<endl;
     cin>>name1>>name2;
     cout<<"please input your address"<<endl;
     cin>>address1>>address2;
     cout<<"your name is "<<name1<<name2<<endl;
     cout<<"your address is"<<address1<<address2<<endl;
     return 0;
}
还有这个。。。。。好难啊
2011-01-11 23:08
zgxyz2008
Rank: 4
等 级:业余侠客
帖 子:67
专家分:202
注 册:2008-10-28
收藏
得分:1 
楼主,我都编译了一次,都能正常执行,是不是你建项目时没建对哦,要不就是RP的问题了~
2011-01-12 15:19
快速回复:程序运行总是出错,不知道为什么,请教各位帮忙
数据加载中...
 
   



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

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