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 这个文件,这样怎么整