这是this question的一种副本。我按照建议(我认为)并包括<string>
,但我的脸上却出现了完全相同的错误:
错误C2679:二进制'&lt;&lt;' :找不到哪个操作员需要右手 'std :: string'类型的操作数(或者没有可接受的转换)
#include <string>
#include <iostream>
using namespace std;
int main() {
string texte;
texte = "pouet";
wcout << texte << endl;
return 0;
}
编辑:我并不自豪地说这个问题是由于我没有选择正确的项目作为“启动项目”。 Visual Studio有点难以理解......然而,最初的真正问题涉及我的真实项目,并且是关于无法通过wcout
输出的标准字符串。我重新格式化了问题,以便相应地重新定位主题。按照你的意愿向我倾倒,我应得的......
答案 0 :(得分:2)
输出运算符不会因std::basic_string
而重载,以便为流的任意字符类型操作。您的选择是:
从std::wstring
创建std::string
,例如:
std::wcout << std::wstring(texte.begin(), texte.end());
由于输出运算符因C字符串而过载,即使字符类型不匹配,也只能得到一个字符数组:
std::wcout << texte.c_str();
答案 1 :(得分:1)
如果你使用wcout,你也必须使用wstring,你必须在你的const字符串前放一个'L'。
array (
'name' => 'some_dropdown',
'studio' => 'visible',
'label' => 'LBL_MY_LABEL',
'customCode' => '',
'customCodeRenderField' =>,
答案 2 :(得分:1)
使用最新的MinGW编译并在我的CLion上运行正常
#include <string>
#include <iostream>
using namespace std;
int main() {
string texte;
texte = "pouet";
cout << texte << endl;
return 0;
}
对于wcout,又称宽字符串,这应该提供正确的输出:
#include <string>
#include <iostream>
using namespace std;
int main() {
wstring texte;
texte = L"pouet";
wcout << texte << endl;
return 0;
}
cout输出'常规'字符串,字符宽度为1字节(通常为ASCII),而wcout用于“宽”字符串,由表示占用超过1个字节的字符组成。
答案 3 :(得分:0)
你嫁给了字符串类型吗?您可以通过将texte设为char *而不是字符串来执行您要执行的操作:
char* texte = "pouet";