问题
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