| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 853 人关注过本帖
标题:string在cout的时候出了转换的问题
只看楼主 加入收藏
nubore
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2010-9-14
结帖率:50%
收藏
 问题点数:0 回复次数:4 
string在cout的时候出了转换的问题
程序代码:
#include <iostream>
#include <cstring>

using namespace std;

...
...
...


void TestType()
    {
        string Type;
        if ( TypeOfTaxer == 's' || TypeOfTaxer == 'S' )
            Type = "Single";
        else if ( TypeOfTaxer == 'm' || TypeOfTaxer == 'M' )
            Type = "Married";
        else if ( TypeOfTaxer == 'w' || TypeOfTaxer == 'W' )
            Type = "Widowed";
        else if ( TypeOfTaxer == 'd' || TypeOfTaxer == 'D' )
            Type = "Divorced";
        else if ( TypeOfTaxer == 'h' || TypeOfTaxer == 'H' )
            Type = "Head of Family";
        else
            Type = "None";

        cout << "\n\n\tFor This Year, You Declared Yourself as : "  << Type << " !\n";
    }

在 << Type 的时候出错, 我的string用法写错了?

error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(679): could be 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const char *)'
搜索更多相关主题的帖子: color 
2011-02-06 09:35
leeco
Rank: 4
等 级:贵宾
威 望:10
帖 子:1029
专家分:177
注 册:2007-5-10
收藏
得分:0 
你没包含 string的头文件
2011-02-08 01:17
pangding
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:北京
等 级:贵宾
威 望:94
帖 子:6784
专家分:16751
注 册:2008-12-20
收藏
得分:0 
嗯,应该就是 2楼 说的那问题。
2011-02-08 09:28
lucky563591
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:4
帖 子:765
专家分:2103
注 册:2009-11-18
收藏
得分:0 
错误信息是什么呢?
2011-02-09 09:25
gsdgold
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2010-6-9
收藏
得分:0 
#include <cstring>改成下面这个看看
#include<string>
我也是新手 但愿能帮到你
2011-02-28 23:15
快速回复:string在cout的时候出了转换的问题
数据加载中...
 
   



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

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