include string,string不命名一个类型 [英] include string, string doesn't name a type
本文介绍了include string,string不命名一个类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经包含字符串,只是在头文件中的struct中调用一个字符串变量。
我得到'字符串不命名一个类型'为字符串原始和目的地城市,尽管调用字符串之前它
// sortedListClass.h(几行注释)
#include< string>
struct flightRec {
int flightnumber;
string源; // 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:错误:
'string'未命名类型
sortedListClass.h:11:5:错误:
$
'string'不命名类型解决方案p>
std :: string
,除非你用使用
指令(你不应该在头)。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 ausing
directive (which you shouldn't do in a header).这篇关于include string,string不命名一个类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文