| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1014 人关注过本帖
标题:简单问题 哪里错了....我菜鸟
只看楼主 加入收藏
momo1212825
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2008-4-16
收藏
 问题点数:0 回复次数:6 
简单问题 哪里错了....我菜鸟
#include<iostream>
#include<cstring>
int main()
{
    using namespace std;
    cout<<"Enter a word:";
    string word;
    cin>>word;
    char temp;
    int i,j;
    for(j=0,i=word.size()-1;j<i;--i,++j)
    {
        temp=word[i];
        word[i]=word[j];
        word[j]=temp;
    }
    cout<<word<<"\nDone\n";
    return 0;
}

E:\Program Files\Microsoft Visual Studio\MyProjects\1111\111.cpp(8) : 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 conversion)
E:\Program Files\Microsoft Visual Studio\MyProjects\1111\111.cpp(17) : 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 conversion)
搜索更多相关主题的帖子: word Microsoft 简单问题 std 
2008-04-24 07:32
heyyroup
Rank: 1
等 级:新手上路
帖 子:77
专家分:0
注 册:2006-6-14
收藏
得分:0 
这已经很明显了,string 类里面没有重载"<<",">>"操作符,你用的是VC6.0吗,查查MSDN就可以看到string 类的详细内容了。
2008-04-24 09:07
momo1212825
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2008-4-16
收藏
得分:0 
恩 我用的6.0  MSDN怎么查啊...请指教,,,,
2008-04-24 09:14
crosoli
Rank: 1
等 级:新手上路
帖 子:57
专家分:0
注 册:2007-4-24
收藏
得分:0 
#include<iostream>
#include<string>
using namespace std;

int main()
{
    string word;
    cout<<"Enter a word:";
    cin>>word;
    char temp;
    int i,j;
    for(j=0,i=word.size()-1;j<i;--i,++j)
    {
        temp=word[i];
        word[i]=word[j];
        word[j]=temp;
    }
    cout<<word<<"\nDone\n"<<endl;
    return 0;
}


至多一个C,注意格式,养成习惯
2008-04-24 13:02
忘记喧嚣
Rank: 1
等 级:新手上路
帖 子:146
专家分:0
注 册:2007-10-7
收藏
得分:0 
把#include<cstring> 改成:
#include<string>

OK!

还有就是最好
#include<iostream>
#include<string>
using namespace std;
int main()
{
    //using namespace std;
    cout<<"Enter a word:";
    string word;
    cin>>word;
    char temp;
    int i,j;
    for(j=0,i=word.size()-1; j<i; --i,++j)
    {
        temp=word[i];
        word[i]=word[j];
        word[j]=temp;
    }
    cout<<word<<"\nDone\n";
    return 0;
}
这样写
收到的鲜花
  • momo12128252008-04-24 21:35 送鲜花  1朵   附言:谢谢哦
2008-04-24 13:07
momo1212825
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2008-4-16
收藏
得分:0 
谢谢咯
2008-04-24 21:35
wsz317sky
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-4-27
收藏
得分:0 
<cstring>
定义的一些字符串的函数,比如strcpy(),strlen()等等。
<string>
定义了string类
2008-04-27 16:26
快速回复:简单问题 哪里错了....我菜鸟
数据加载中...
 
   



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

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