Why do we get the build error “error C2065: 'ostringstream' : undeclared identifier” & How to fix this?

五迷三道 提交于 2020-02-04 09:35:23

问题


Hi I am compilinig a C++ solution in VS2008.

 ostringstream      strout; 

I am getting the compilation error "error C2065: 'ostringstream' : undeclared identifier".

I feel I have included all the necessary header files.

Can anyone kindly let me know how to fix this error (What all header files to include) ?

Also I am getting a strange error like "error C2146: syntax error : missing ';' before identifier 'strout'" at the same line.

Whereas I know that I havent missed ";" semi-colon @ the line whre the error is being thrown.

Thanks IN advance.


回答1:


We can't tell you what's wrong with your code for sure, unless you show it to us.

But you can use the following and an example on how to do it:

#include <iostream>
#include <sstream>

int main() {
    std::ostringstream oss;
    oss << "Hello";
    std::cout << oss.str() << '\n';
    return 0;
}

The most likely cause is that you haven't actually included all the needed header files which is why it wouldn't recognise ostringstream.

And it's that lack of recognition that's probably causing the missing semicolon error.




回答2:


You need to

#include <sstream>

and qualify the name std::ostringstream.



来源:https://stackoverflow.com/questions/9850527/why-do-we-get-the-build-error-error-c2065-ostringstream-undeclared-identif

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!