visual studio 2012-简单的C++程序不使用wstrings和cout进行编译
visual studio 2012 - Simple C++ program not compiling using wstrings and cout
我正在使用Visual Studio 2012:构建这个简单的C++程序
#include <stdafx.h>
#include <string>
#include <iostream>
int main()
{
std::wcout << "Hello World...";
std::string input_data;
std::string output_data("Hello. Please type your name");
std::wcout << output_data;
std::wcin >> input_data;
std::wcout << "Your name is " << input_data;
return 0;
}
我不会编译。获得以下错误:
error C2678: binary '>>' : no operator found which takes a left-hand operand of type 'std::wistream' (or there is no acceptable conversion)
error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
IntelliSense: no operator "<<" matches these operands
operand types are: std::basic_ostream<wchar_t, std::char_traits<wchar_t>> << std::string
IntelliSense: no operator "<<" matches these operands
operand types are: std::wostream << std::string
IntelliSense: no operator ">>" matches these operands
operand types are: std::wistream >> std::string
有人能帮我修一下吗?
您应该尝试更改std::wstring
的所有std::string
位置。。。或者全部wcin
/wcout
用于cin
/cout
。。。(在第一种情况下,为字符串加前缀,如L"aaa"
。例如,这非常有效:
#include <string>
#include <iostream>
int main()
{
std::wcout << L"Hello World...";
std::wstring input_data;
std::wstring output_data(L"Hello. Please type your name");
std::wcout << output_data;
std::wcin >> input_data;
std::wcout << L"Your name is " << input_data;
return 0;
}
或者,您可以将所有内容切换为窄字符串:
#include <string>
#include <iostream>
int main()
{
std::cout << "Hello World...";
std::string input_data;
std::string output_data("Hello. Please type your name");
std::cout << output_data;
std::cin >> input_data;
std::cout << "Your name is " << input_data;
return 0;
}
相关文章:
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- std::cout.imbue()多重调用
- 如何在C++中用std::cout正确显示带十六进制的字符串文本
- 为什么在C的循环中使用printf的Rust代码不显示输出,而在C++的循环中显示std::cout
- 为什么我应该在异常处理中使用std::cerr而不是std::cout
- 在作为静态成员包含在另一个类中的类的构造函数中使用 cout
- 在 COUT 语句中使用 COUT 调用函数
- GCC 4.8.2 自动矢量化由于 cout 而失败
- std::cout输出int时出现编译错误
- 在这种情况下显式调用时,std::cout 如何更改析构函数的行为?
- C++ Setter/Getter,cout 工作,printf 失败
- C++ cout 将双精度对齐到精度 2 并正确对齐
- 结构元素名称要 cout?
- 使用模板类重载 cout
- 犰狳的 print() 方法和 cout 在从 Rcpp 调用时顺序不一致
- 带有 cout 的指针在C++
- cout 指针时的实际数字
- COUT 无法提供输出可能是由于内联组装
- C++程序在一定行后未正确编译[cout语句]
- visual studio 2012-简单的C++程序不使用wstrings和cout进行编译