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 *)'