怎么将一个函数放到头文件中?
是这样的,我写了一个函数get,再get.h文件中申明了,然后再get.cpp中实现,再main.cpp中使用,但是出现了错误
求解
get.h
#ifndef GET_H_INCLUDED#define GET_H_INCLUDEDextern istream &get(istream& gt)#endif // GET_H_INCLUDED
#include <iostream>#include <stdexcept>#inlucde "get.h"using namespace std;istream &get(istream& gt){ string a; while(gt>>a) { if(gt.bad()) throw runtime_error("iostream is corrupted"); cout<<a<<endl; } return gt;}
#include <iostream>#include "get.h"using namespace std;int main(){ double ival; get(cin); cin>>ival; cout<<ival; return 0;}
// get.h#ifndef GET_H_INCLUDED#define GET_H_INCLUDED#include<iostream>using std::istream;istream &get(istream& gt);#endif // GET_H_INCLUDED
[解决办法]
extern istream &get(istream& gt);
[解决办法]
你那个include写错啦