![]() |
#2
rjsp2013-03-19 08:34
|

编写的函数放在这个文件里 get.hpp
复制内容到剪贴板
代码:
istream& get(istream& in){
int i;
while(in>>i,!in.eof()){
if(in.bad())
throw runtime_error("IO stream corrupted");
if(in.fail()){
cerr<<"bad data,try again";
in.clear;
in.ignore(200,'');
continue;
}
cout<<i<<endl;
}
in.clear();
return in;}
在这个源函数里调用
复制内容到剪贴板
代码:
#include"get.hpp"
#include<iostream>
#include<stdexcept>
using namespace::std;
int main(){
double j;
cin>>j;
get(cin);
return 0;
}
出现了
--------------------配置: mingw5 - CUI Release, 编译器类型: MinGW--------------------
检查文件依赖性...
正在编译 C:\Users\Think\Desktop\习题\8.4.cpp...
[Error] C:\Users\Think\Desktop\习题\get.hpp:2: error: expected constructor, destructor, or type conversion before '&' token
[Error] C:\Users\Think\Desktop\习题\get.hpp:10:18: empty character constant
[Warning] C:\Users\Think\Desktop\习题\get.hpp:16:12: warning: no newline at end of file
[Error] C:\Users\Think\Desktop\习题\8.4.cpp:9: error: `get' was not declared in this scope
[Warning] C:\Users\Think\Desktop\习题\8.4.cpp:12:2: warning: no newline at end of file
构建中止 8.4: 3 个错误, 2 个警告
这种错误 ,求指导
复制内容到剪贴板
代码:
istream& get(istream& in){
int i;
while(in>>i,!in.eof()){
if(in.bad())
throw runtime_error("IO stream corrupted");
if(in.fail()){
cerr<<"bad data,try again";
in.clear;
in.ignore(200,'');
continue;
}
cout<<i<<endl;
}
in.clear();
return in;}
在这个源函数里调用
复制内容到剪贴板
代码:
#include"get.hpp"
#include<iostream>
#include<stdexcept>
using namespace::std;
int main(){
double j;
cin>>j;
get(cin);
return 0;
}
出现了
--------------------配置: mingw5 - CUI Release, 编译器类型: MinGW--------------------
检查文件依赖性...
正在编译 C:\Users\Think\Desktop\习题\8.4.cpp...
[Error] C:\Users\Think\Desktop\习题\get.hpp:2: error: expected constructor, destructor, or type conversion before '&' token
[Error] C:\Users\Think\Desktop\习题\get.hpp:10:18: empty character constant
[Warning] C:\Users\Think\Desktop\习题\get.hpp:16:12: warning: no newline at end of file
[Error] C:\Users\Think\Desktop\习题\8.4.cpp:9: error: `get' was not declared in this scope
[Warning] C:\Users\Think\Desktop\习题\8.4.cpp:12:2: warning: no newline at end of file
构建中止 8.4: 3 个错误, 2 个警告
这种错误 ,求指导