返回列表 回复 发帖

请问:宽字符如何定义?

#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
        wchar_t cH;
        cin>>cH;
        cout<<cH;
        return 0;
}
结果出错错误信息如下:
f:\my documents\visual studio 2008\projects\dddddd\dddddd\dddddd.cpp(9) : error C2679: 二进制“>>”: 没有找到接受“wchar_t”类型的右操作数的运算符(或没有可接受的转换)
        e:\program files\microsoft visual studio 9.0\vc\include\istream(1144): 可能是“std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,signed char *)”
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        e:\program files\microsoft visual studio 9.0\vc\include\istream(1146): 或       “std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,signed char &)”
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        e:\program files\microsoft visual studio 9.0\vc\include\istream(1148): 或       “std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,unsigned char *)”
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        e:\program files\microsoft visual studio 9.0\vc\include\istream(1150): 或       “std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,unsigned char &)”
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        e:\program files\microsoft visual studio 9.0\vc\include\istream(155): 或       “std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_istream<_Elem,_Traits> &(__cdecl *)(std::basic_istream<_Elem,_Traits> &))”
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        e:\program files\microsoft visual studio 9.0\vc\include\istream(161): 或       “std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_ios<_Elem,_Traits> &(__cdecl *)(std::basic_ios<_Elem,_Traits> &))”
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        e:\program files\microsoft visual studio 9.0\vc\include\istream(168): 或       “std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::ios_base &(__cdecl *)(std::ios_base &))”
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        e:\program files\microsoft visual studio 9.0\vc\include\istream(175): 或       “std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::_Bool &)”
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        e:\program files\microsoft visual studio 9.0\vc\include\istream(194): 或       “std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(short &)”
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        e:\program files\microsoft visual studio 9.0\vc\include\istream(228): 或       “std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(unsigned short &)”
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        e:\program files\microsoft visual studio 9.0\vc\include\istream(247): 或       “std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(int &)”
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        e:\program files\microsoft visual studio 9.0\vc\include\istream(273): 或       “std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(unsigned int &)”
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        e:\program files\microsoft visual studio 9.0\vc\include\istream(291): 或       “std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(long &)”
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        e:\program files\microsoft visual studio 9.0\vc\include\istream(309): 或       “std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(__w64 unsigned long &)”
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        e:\program files\microsoft visual studio 9.0\vc\include\istream(329): 或       “std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(__int64 &)”
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        e:\program files\microsoft visual studio 9.0\vc\include\istream(348): 或       “std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(unsigned __int64 &)”
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        e:\program files\microsoft visual studio 9.0\vc\include\istream(367): 或       “std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(float &)”
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        e:\program files\microsoft visual studio 9.0\vc\include\istream(386): 或       “std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(double &)”
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        e:\program files\microsoft visual studio 9.0\vc\include\istream(404): 或       “std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(long double &)”
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        e:\program files\microsoft visual studio 9.0\vc\include\istream(422): 或       “std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(void *&)”
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        e:\program files\microsoft visual studio 9.0\vc\include\istream(441): 或       “std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_streambuf<_Elem,_Traits> *)”
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        试图匹配参数列表“(std::istream, wchar_t)”时
你的赋值方式有错误。可以参考:http://developer.51cto.com/art/200908/147495.htm
返回列表