Visual Studio 2015 & 2017 doesn't recognize std

Elinor Ginzburg 106 Reputation points
2020-08-25T04:58:53.277+00:00

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.

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,512 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,481 questions
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
35,516 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. WayneAKing 4,921 Reputation points
    2020-08-25T07:03:38.34+00:00

    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
    0 comments No comments

  2. Elinor Ginzburg 106 Reputation points
    2020-08-25T11:16:17.48+00:00

    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""


  3. Jeanine Zhang-MSFT 8,771 Reputation points Microsoft Vendor
    2020-08-26T01:56:35.407+00:00

    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>.

    0 comments No comments