为什么我不能cout string : string text ; text = WordList[i].substr(0,20) ; cout << "String is : " << text << endl ; 当我这样做,我得到以下错误: 错误2错误C2679:二进制'<<':没有find操作符'std :: string'types的右边操作数(或没有可接受的转换)c:\ users \ mollasadra \ documents \ visual studio 2008 \ projects \ barnamec \ barnamec \ barnamec.cpp 67 barnamec ** 令人惊讶的是,即使这不起作用: string text ; text = "hello" ; cout << […]
我想要做: int a = 255; cout << a; 并在输出中显示FF,我将如何做到这一点?
执行一些testing后,我发现printf比cout快得多。 我知道它是依赖于实现的,但在我的Linux机器上, printf速度是8倍。 所以我的想法是混合两种打印方法:我想使用cout来打印简单的图片,并且我打算使用printf来产生巨大的输出(通常是一个循环)。 我认为只要在切换到其他方法之前不要忘记刷新就可以了。 cout << "Hello" << endl; cout.flush(); for (int i=0; i<1000000; ++i) { printf("World!\n"); } fflush(stdout); cout << "last line" << endl; cout << flush; 这样可以吗? 更新:感谢所有宝贵的反馈。 答案总结:如果你想避免棘手的解决scheme,只是简单地不要使用带有cout endl ,因为它隐式地刷新缓冲区。 改用"\n" 。 如果产生大量输出,这可能会很有趣。
我正在试图打印一个俄文“ф”( U + 0444 CYRILLIC SMALL LETTER EF)字符,该字符被赋予十进制数1092 。 使用C ++,我怎样才能打印出这个字符? 我会认为沿着下面的路线的东西会工作,但… int main (){ wchar_t f = '1060'; cout << f << endl; }
我想cout输出一个前导零的整数,所以值1将打印为001和值25打印为025 ..你明白了..我怎么能做到这一点? 谢谢。
我想用C ++打印一个vector的内容,这里是我的: #include <iostream> #include <fstream> #include <string> #include <cmath> #include <vector> #include <sstream> #include <cstdio> using namespace std; int main() { ifstream file("maze.txt"); if (file) { vector<char> vec(istreambuf_iterator<char>(file), (istreambuf_iterator<char>())); vector<char> path; int x = 17; char entrance = vec.at(16); char firstsquare = vec.at(x); if (entrance == 'S') { path.push_back(entrance); } for (x = 17; […]
printf()和cout在C ++中有什么区别?
下面的代码: myQueue.enqueue('a'); myQueue.enqueue('b'); cout << myQueue.dequeue() << myQueue.dequeue(); 打印“ba”到控制台 而: myQueue.enqueue('a'); myQueue.enqueue('b'); cout << myQueue.dequeue(); cout << myQueue.dequeue(); 打印“ab”这是为什么? 似乎cout正在调用最靠外的函数(最接近这个函数)并且正在工作,它的行为方式是什么?
所以我已经得到了最后一个问题的答案(我不知道为什么我没有想到这一点)。 我正在用cout打印一个double ,当我不期待的时候。 我怎样才能让cout使用全精度打印double精度?