写了个文件输出类报错

JPF1024 2014-03-30 11:59:48
不知道为什么就报错了,求解答。

头文件:


#ifndef TEST822_H
#define TEST822_H


class Test822
{
public:
Test822();
int reads(std::iostream &is,std::ofstream &os);
void out(std::ifstream &ins);
protected:
private:
};

#endif // TEST822_H



实现:

#include "Test822.h"
#include<iostream>
#include<fstream>

int Test822::reads(istream &is,ofstream &os)
{
string pos ;
is >> pos ;
os << pos ;
return 0;
}

Test822::out(ifstream &kis)
{
string pos;
while(kis >> pos)
{
cout << pos << endl;
}

}


main方法:

#include <iostream>
#include<fstream>
//#include"Test822.cpp"
#include"Test822.h"
using namespace std;

int main()
{
ofstream iks("F:\\test.txt");
Test822 test;
test.reads(cin,iks);
cout << "输出." << endl;
iks.close();
ifstream ins("F:\\test.txt");
test.out(ins);
ins.close();
return 0;
}


编译记录:



-------------- Build: Debug in 822Out (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -Wall -fexceptions -g -std=c++0x -Iinclude -c main.cpp -o obj\Debug\main.o
main.cpp: In function 'int main()':
main.cpp:11:23: error: no matching function for call to 'Test822::reads(std::istream&, std::ofstream&)'
test.reads(cin,iks);
^
main.cpp:11:23: note: candidate is:
In file included from main.cpp:4:0:
include/Test822.h:9:13: note: int Test822::reads(std::iostream&, std::ofstream&)
int reads(std::iostream &is,std::ofstream &os);
^
include/Test822.h:9:13: note: no known conversion for argument 1 from 'std::istream {aka std::basic_istream<char>}' to 'std::iostream& {aka std::basic_iostream<char>&}'
Process terminated with status 1 (0 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))






刚学没多久,对C++的类很迷茫,求指点迷津,谢谢
...全文
93 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
sysphius 2014-04-16
  • 打赏
  • 举报
回复
头文件里面没有#include<iostream>,所以默默地报错了,系统找不到你要用的IO对象。
turing-complete 2014-03-30
  • 打赏
  • 举报
回复
至少有一个我问题是: cpp 文件中没有 using namespace std;
JPF1024 2014-03-30
  • 打赏
  • 举报
回复
引用 1 楼 mougaidong 的回复:
至少有一个我问题是: cpp 文件中没有 using namespace std;
修改了还是报错,说类找不到

64,683

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧