首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

一个C++的函数,该怎么解决

2012-02-07 
一个C++的函数#include iostream#include fstream#include cstdlib#include stringusing namespac

一个C++的函数
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>

using namespace std;
int Kg_get (istream, string, int);
int main ()
{
  string buffer;
  int crypLength = 3;
  ifstream instream("source");
  int isend;
  while ( (isend = Kg_get(instream, buffer, crypLength)) != 0)
  {
  cout << buffer << endl;
  }
  return 0;
}
//Kg_get()函数从文件中读取指定的字节数,并将数据写入字符串str中
int Kg_get (istream &in, string str, int length)
{
  str = ""; //首先将str清空
  char ch;
  while ( (ch = in.get()) != EOF && length != 0)
  {
  str += ch;
  length --;
  }
  if ( length != 0)
  return 0; //说明文件结束导致读取结束
  else
  return 1; //正常结束
}
请各位大虾帮帮忙,函数总是出错(函数写的不好,还请大家多多指教),在vc下是连接错误,在codeblock下是不知道什么错误,
错误可能出在int Kg_get (istream &in, string str, int length)这个函数参数上,可怎么找也找不着,还请大家多多帮忙,谢了先。

[解决办法]
你的函数声明写错了

int Kg_get (istream , string, int);

==>

int Kg_get (istream &, string, int);

热点排行