aaasdfgzzy 2022-11-14 22:35 采纳率: 79.4%
浏览 12
已结题

c++(多文件类引入、定义、使用)

head.h

#include<iostream>
#include<string>
using namespace std;
class Car
{
    private:
        string colour;
        double weight;
    public:
        void set(string c_colour,double c_weight);
        void print();
};

c++define.cpp

#include "head.h"
#include<iostream>
#include<string>
using namespace std;

void Car:: set(string c_colour,double c_weight)
{
    colour = c_colour;
    weight = c_weight;
}

void Car :: print()
{
    cout << "colour: " << colour << "\nweight: " << weight << endl;
}

c++use.cpp

#include "head.h"
#include<iostream>
#include<string>

using namespace std;
int main()
{
    Car c;
    string colour;
    double weight;
    cout << "colour: ";
    cin >> colour;
    cout << "weight: ";
    cin >> weight;
    c.set(colour,weight);
    c.print();
    return 0;
}
//程序在这里编译后显示  :没有 head.h 这个文件,这样怎么整
  • 写回答

2条回答 默认 最新

  • 伍六七0804 2022-11-15 15:12
    关注
    #include <头文件>  : 编译器只会从系统配置的库环境中去寻找头文件,不会搜索当前文件夹。通常用于引用标准库头文件。
    #include "头文件"  : 编译器会先从当前文件夹中寻找头文件,如果找不到则到系统默认库环境中去寻找。一般用于引用用户自己定义使用的头文件。
    改成
    #include “head.h”
    
    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 11月29日
  • 修改了问题 11月16日
  • 修改了问题 11月15日
  • 修改了问题 11月14日
  • 展开全部

悬赏问题

  • ¥15 关于#Stata#的问题:数据是面板数据,SPSS里面不能控制年份和时间,所以只能用Stata做
  • ¥20 基于基于NioEventLoop线程阻塞问题
  • ¥20 我需要"hill48屈服模型 等向强化 非线性硬化"的abaqus本构子程序(umat或者vumat)对应的理论推导过程。
  • ¥15 基于ucc28019的pfc电路中芯片一直不工作
  • ¥15 yolov8在3588板子端c++推理报错
  • ¥50 unitywebrequest分段下载导致报错,如何解决?
  • ¥15 错误使用 gretna_GUI_PreprocessInterface>RunBtn_Callback
  • ¥15 WPF如何用Chart绘画出Y轴的左边数据
  • ¥20 系统重装后Calibre无法启动
  • ¥15 跑hls xfopencv的例程standalone_hls_axi_example出的错误,csim没问题,c synthesis出的错误