Why do we get the build error “error C2065: 'o

2019-07-16 12:35发布

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.

2条回答
SAY GOODBYE
2楼-- · 2019-07-16 13:06

You need to

#include <sstream>

and qualify the name std::ostringstream.

查看更多
何必那么认真
3楼-- · 2019-07-16 13:11

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.

查看更多
登录 后发表回答