Dragos Rizescu
Dragos Rizescu

Reputation: 3488

Using string in a class c++ outputs error

I want to create a C++ class that uses the string library. Here is my source code:

test.h:

#include <string>


class info {
public:
    // constructor
    info (string first_name, string last_name, int age);
    // deconstructor
    ~info ();



private:
    string first_name;
    string last_name;
    int age;

};

And here is my header assist file: test.cpp

#include <string>
#include "test.h"


info::info (string first_name, string last_name, int age) {
    this->first_name = first_name;
    this->last_name = last_name;
    this->age = age;

}
info::~info () {
}

However it gives me syntax error: identifier "string" is undefined

Why is that? I am kinda a noobie to C++ Data Structures

Also, I am compiling this is Visual Studio 2012

Upvotes: 0

Views: 108

Answers (1)

David G
David G

Reputation: 96790

You need to have std:: before string as you are using a qualified name (an identifier in the namespace std).

For example, you constructor should look like this:

info (std::string const& first_name, std::string const& last_name, int age);

Upvotes: 3

Related Questions