一个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);