question

ElinorGinzburg-9950 avatar image
0 Votes"
ElinorGinzburg-9950 asked JeanineZhang-MSFT answered

Visual Studio 2015 & 2017 doesn't recognize std

Hello,



I've written simple piece of code which compiles and works perfectly on any other program which can compile and run C++,

but when I try to run it from VS 2015 on my laptop or on VS 2017 from my other laptop, it won't build it - I get an error saying it doesn't recognize std e.g. it says "string is not a member of std"

I've checked and I think that I've installed all necessary extensions for C++ to work.

How can I fix it?



Thank you.

c++vs-generalvs-msbuildvs-extensions
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

WayneAKing-0228 avatar image
0 Votes"
WayneAKing-0228 answered

Show a small but complete example of code that produces that error.

Also be sure that you have the right #include statement:

 #include <string>

  • Wayne

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ElinorGinzburg-9950 avatar image
0 Votes"
ElinorGinzburg-9950 answered RLWA32-6355 edited

the code:

 std::ostringstream ss;
 int i = 7;
    
 ss << std::hex << std::showbase << i;
    
 std::string str = ss.str();
    
 const char *output = str.c_str();

the headers I've included:

 #include <stdlib>
 #include <iostream>
 #include <sstream>
 #include <iomanip>
 #include <string>
 #include <strstream>

I also get an error "cannot open source file "stdlib""

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

After making a small correction -
#include <cstdlib>
the posted code compiled without error on my VS2015 Community and VS2017 Community.


0 Votes 0 ·
JeanineZhang-MSFT avatar image
0 Votes"
JeanineZhang-MSFT answered

As far as I'm concerned, you should use "#include<stdlib.h>" instead of "#include<stdlib>".

And I agree with RLWA32, you could try to use "#include <cstdlib>". It includes the C Standard library header <stdlib.h> and adds the associated names to the std namespace. For more details I suggest you could refer to the Doc:<cstdlib>.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.