C++ ostringstream运营商<&书信电报;很久了? $uname-a Darwin Wheelie Cyberman 10.8.0 Darwin内核版本10.8.0:Tue Jun 7 16:33:36 PDT 2011;根目录:xnu-1504.15.3~1/RELEASE_I386 I386 $g++--版本 i686-apple-darwin10-g++-4.2.1(GCC)4.2.1(apple Inc.build 5666)(dot 3) 版权所有(C)2007免费软件基金会。 这是自由软件;有关复制条件,请参见源。没有 担保甚至不是为了适销性或适合某一特定目的。 $cat nolove.cc #包括 #包括 使用名称空间std; int main(int argc,字符**argv){ 无符号长i=0; ostringstream o(); //编撰精良 这是因为 $ uname -a Darwin Wheelie-Cyberman 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun 7 16:33:36 PDT 2011; root:xnu-1504.15.3~1/RELEASE_I386 i386 $ g++ --version i686-apple-darwin10-g++-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3) Copyright (C) 2007 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ cat nolove.cc #include <iostream> #include <sstream> using namespace std; int main(int argc, char ** argv) { unsigned long long i = 0; ostringstream o(); // Compiles fine cout << i; // Explodes, see below o << i; return 0; } $ g++ -o nolove nolove.cc nolove.cc: In function ‘int main(int, char**)’: nolove.cc:14: error: invalid operands of types ‘std::ostringstream ()()’ and ‘long long unsigned int’ to binary ‘operator<<’

C++ ostringstream运营商<&书信电报;很久了? $uname-a Darwin Wheelie Cyberman 10.8.0 Darwin内核版本10.8.0:Tue Jun 7 16:33:36 PDT 2011;根目录:xnu-1504.15.3~1/RELEASE_I386 I386 $g++--版本 i686-apple-darwin10-g++-4.2.1(GCC)4.2.1(apple Inc.build 5666)(dot 3) 版权所有(C)2007免费软件基金会。 这是自由软件;有关复制条件,请参见源。没有 担保甚至不是为了适销性或适合某一特定目的。 $cat nolove.cc #包括 #包括 使用名称空间std; int main(int argc,字符**argv){ 无符号长i=0; ostringstream o(); //编撰精良 这是因为 $ uname -a Darwin Wheelie-Cyberman 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun 7 16:33:36 PDT 2011; root:xnu-1504.15.3~1/RELEASE_I386 i386 $ g++ --version i686-apple-darwin10-g++-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3) Copyright (C) 2007 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ cat nolove.cc #include <iostream> #include <sstream> using namespace std; int main(int argc, char ** argv) { unsigned long long i = 0; ostringstream o(); // Compiles fine cout << i; // Explodes, see below o << i; return 0; } $ g++ -o nolove nolove.cc nolove.cc: In function ‘int main(int, char**)’: nolove.cc:14: error: invalid operands of types ‘std::ostringstream ()()’ and ‘long long unsigned int’ to binary ‘operator<<’,c++,long-integer,cout,ostringstream,C++,Long Integer,Cout,Ostringstream,不声明变量,而是返回流的函数 试试这个 ostringstream o(); 另见 嗯。谢谢!我以为我是在确保调用默认构造函数(一位朋友最近向我描述了与“pod”类型有关的一些问题。)当()与类型名称一起使用时,它可以是一个初始值设定项,如new int()。当在声明操作中与非类型名称一起使用时,它声明一个函数,如f()(在您的示例中为o())。 ostringstream o;

不声明变量,而是返回流的函数

试试这个

ostringstream o(); 
另见


嗯。谢谢!我以为我是在确保调用默认构造函数(一位朋友最近向我描述了与“pod”类型有关的一些问题。)当
()
与类型名称一起使用时,它可以是一个初始值设定项,如
new int()
。当在声明操作中与非类型名称一起使用时,它声明一个函数,如
f()
(在您的示例中为
o()
)。
ostringstream o;