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?
It's called std::string
unless you put in a using
directive (which you shouldn't do in a header).
精彩评论