1

I have included string and just after call a string variable in a struct in an header file. I get the 'string doesn't name a type' for string Origin and Destination City, despite calling string just before it

//sortedListClass.h (a few lines of comments)
#include <string>
struct flightRec{
    int flightnumber;
    string Origin; //problem #1
    string DestinationCity; // problem #2
    float cost;
    flightRec* ptr;
};
typedef flightRec* nodeptr;
#ifndef SORTEDLISTCLASS_H
#define SORTEDLISTCLASS_H
#include <iostream>
#include <cassert>

sortedListClass.h:10:5: error: ‘string’ does not name a type

sortedListClass.h:11:5: error: ‘string’ does not name a type

Might I ask what am I doing wrong?

1 Answer 1

8

It's called std::string unless you put in a using directive (which you shouldn't do in a header).

Sign up to request clarification or add additional context in comments.

1 Comment

Ah, yes... I tried string::string instead and it didn't work. Thank you. I forgot it was in std.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.