小编rea*_*ash的帖子

C++类无法识别字符串数据类型

我正在研究我的C++教科书中的程序,这是我第一次遇到麻烦.我似乎无法看到这里有什么问题.Visual Studio告诉我错误:标识符"string"未定义.

我将程序分成三个文件.类规范的头文件,类实现的.cpp文件和主程序文件.这些是我书中的说明:

编写一个名为Car的类,它具有以下成员变量:

一年.一个int是拥有汽车的车型年.

制作.一个string持有汽车制造的.

速度.一个int是拥有汽车的当前速度.

此外,该类应具有以下成员函数.

构造函数.构造函数应该接受car yearmakeas作为参数,并将这些值赋给对象yearmake成员变量.构造函数应该将speed成员变量初始化为0.

存取器.适当的存取器函数应创建以允许从一个对象的检索到的值year,makespeed成员变量.

有更多的说明,但没有必要让这部分工作.

这是我的源代码:

// File Car.h -- Car class specification file
#ifndef CAR_H
#define CAR_H
class Car
{
private:
    int year;
    string make;
    int speed;
public:
    Car(int, string);
    int getYear();
    string getMake();
    int getSpeed();
};
#endif


// File Car.cpp -- Car class …
Run Code Online (Sandbox Code Playgroud)

c++ string constructor

13
推荐指数
3
解决办法
3万
查看次数

标签 统计

c++ ×1

constructor ×1

string ×1