开发者

C++ error no such file or directory

开发者 https://www.devze.com 2023-01-19 08:24 出处:网络
Hey guys, Ijust started learning C++ and I have this code that I have to complete but the class header is giv开发者_高级运维ing me this error

Hey guys, I just started learning C++ and I have this code that I have to complete but the class header is giv开发者_高级运维ing me this error

error: string: No such file or directory

#include <vector>
#include <string>

class Inventory
{
public:
    Inventory ();
    void Update (string item, int amount);
    void ListByName ();
    void ListByQuantity ();
private:
    vector<string> items;
};


your code should probably look something more like this:

#include <string>
#include <vector>

class Inventory {
public:
    Inventory();
    void Update(const std::string& item, int amount);
    void ListByName();
    void ListByQuantity();
private:
    std::vector<std::string> items;
};

if #include <string> is in fact your include directive, then you may be compiling the file as a c program. the compiler often determines language by the file extension. what is your file named?


I don't think your error is anything to do with namespaces.

You say you're getting error: string: No such file or directory which implies that the pre-compiler cannot find the STL string definition file. This is quite unlikely if you're also including vector and having no problems with that.

You should check your compilation output for clues about where it's picking header files from. Any chance you could post the full compilation output?


Either use using std::string (not recommended) or replace string with std::string.

Or, if I have misunderstood, use #include <string> instead of #include "string".

Same goes for vector which is also in std namespace.

0

精彩评论

暂无评论...
验证码 换一张
取 消