C++课程结束就没管C++了,现在小学期要写个小项目,但太长时间没有写代码了,可能是一部分固定形式忘了,一直出现了图中的报错,对比了以前的代码,还是没有发现问题所在
根据答主们的回答改了一个小错误,但是还是没能解决提出的问题
主函数
#include <iostream>
#include <fstream>
#include "code_pretreatment_module.h"
using namespace std;
int main()
{
int a;
code_pretreatment_module b;
b.target_openning("target.txt");
b.code_pretreatment();
a=b.box.size();
for(int c=0;c<a;c++)
{
cout<<b.box[c]<<endl;
}
return 0;
}
.h文件
#ifndef CODE_PRETREATMENT_MODULE_H_INCLUDED
#define CODE_PRETREATMENT_MODULE_H_INCLUDED
#include <vector>
using namespace std;
class code_pretreatment_module
{
public:
vector<string> box;
fstream target;
void code_pretreatment();
void target_openning(const char *);
};
#endif // CODE_PRETREATMENT_MODULE_H_INCLUDED
部分.cpp文件
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <cstring>
#include "code_pretreatment_module.h"
using namespace std;
void code_pretreatment_module :: target_openning(const char *target_file)
{
target.open(target,ios::in)
if(!target.is_open())
{
cout<<"ERROR!"<<endl;
return NULL;
}
return;
}
void code_pretreatment();这个函数你没有在CPP中实现啊
fstream target_openning(const char *);这个你在.h中的返回值是fstream,但是在cpp中的返回值类型是void,这是不对的,.h和.cpp中需要一致才行
fstream target_openning(const char *);
函数声明和实现的返回类型不同。