Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 左操作数的类型为';std::stringstream(uu cdecl*)(std::string)和#x27;_C++_Stringstream - Fatal编程技术网

C++ 左操作数的类型为';std::stringstream(uu cdecl*)(std::string)和#x27;

C++ 左操作数的类型为';std::stringstream(uu cdecl*)(std::string)和#x27;,c++,stringstream,C++,Stringstream,两种代码的区别是什么: char buf[2048]; stringstream in(string(buf)); int tmpInt; while ((in >> tmpInt)) { // wrong, error C2296: '>>' : illegal, left operand has type 'std::stringstream (__cdecl *)(std::string)' } 及 我认为它们做的事情是一样的:都使用string来构造stri

两种代码的区别是什么:

char buf[2048];
stringstream in(string(buf));
int tmpInt;

while ((in >> tmpInt)) { // wrong, error C2296: '>>' : illegal, left operand has type 'std::stringstream (__cdecl *)(std::string)'

}

我认为它们做的事情是一样的:都使用string来构造stringstream对象。无论是临时对象还是真实对象,我们都将在stringstream中调用字符串复制构造函数(只需复制buf内容)

IDE:
vs2010

那么,这两种方式有什么不同呢?或stringstream实现方式


谢谢。

克里斯给出了答案。该代码相当于以下代码:

stringstream in(string buf);

C++中,人们称之为:

编译器将其视为函数声明<
中的code>是一个函数,它返回stringstream并接受
字符串作为参数。请注意,编译器在错误消息
std::stringstream(\uu cdecl*)(std::string)
中告诉您这一点

您需要一组额外的括号或C++11统一初始值设定项语法来告诉编译器它不是您要声明的函数:

stringstream in((string(buf)));

stringstream in{string(buf)};

这是最烦人的解析。哦,我明白了。我认为这是一个函数向前声明。谢谢你,杰西。
stringstream in((string(buf)));

stringstream in{string(buf)};