Beginers关于Getline的问题 [英] Beginers Question about Getline

查看:65
本文介绍了Beginers关于Getline的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在编译时不断收到以下错误:

c:\ c ++ files \programs\stellardebug \ unitcode.h(677):错误C2664:

''class istream& __ thiscall istream :: getline(char *,int,char)'':不能

将参数1从''const char *''转换为''char *''

转换失去限定符


我有一个名为Standard.udf的数据文件


数据文件(不是问题):文件中的数据是文本

格式,是使用此程序中带有fout的函数创建的。

使用记事本,我知道数据文件是不是问题。仅供参考:

第一行数据是******************************** *******"我想要跳过它继续下一个。


这是问题功能:


int UnitDef_Load(string sFileName)

{

int iERRORCODE = ERR_NONE;

iERRORCODE = UnitDefCleanList(false); //清理链表

if(iERRORCODE == ERR_NONE)

{

ifstream fin(sFileName.c_str());

if(!fin)//检查文件

{

返回ERR_UNABLE_TO_OPEN; //错误检查

}

其他

{


//这里是代码加载HEADER DATA !!!!

string Temp;

fin.getline(Temp,255); //问题行

};

fin.close();

}; //结束如果

返回iERRORCODE;

};

我已经尝试了所有我知道的工作(我已离开

来自c ++一段时间......刚刚回到它。)

有人可以解释如何使这项工作? (我花了几个小时在网上寻找例子,但没找到一个有效的。)

谢谢。

I keep getting the following error upon compiling:
c:\c++ files\programs\stellardebug\unitcode.h(677) : error C2664:
''class istream &__thiscall istream::getline(char *,int,char)'' : cannot
convert parameter 1 from ''const char *'' to ''char *''
Conversion loses qualifiers

I have a data file called Standard.udf

The Data File (not the problem): The data in the file is in text
format, and was created using a function in this program with fout.
Using notepad, I know the data file is not the problem. FYI: The
first line of data is "***************************************" and I
just want to skip it and go on to the next one.

Here is the problem function:

int UnitDef_Load(string sFileName)
{
int iERRORCODE = ERR_NONE;
iERRORCODE = UnitDefCleanList(false); // cleans linked list
if(iERRORCODE == ERR_NONE)
{
ifstream fin(sFileName.c_str());
if (!fin) // checks for file
{
return ERR_UNABLE_TO_OPEN; // error checking
}
else
{

// HERE IS THE CODE LOADING THE HEADER DATA!!!!
string Temp;
fin.getline(Temp,255); // PROBLEM LINE
};
fin.close();
}; // end if
return iERRORCODE;
};
I have tried everything I know to get this to work (I have been away
from c++ for awhile... just now getting back to it).
Could someone please explain how to make this work? (I have spent
hours online looking for examples, but have not found one that works).
Thank you.

推荐答案

2004年8月23日20:04:36 -0700, th **** ****@houston.rr.com (Skywise)

写道:
On 23 Aug 2004 20:04:36 -0700, th********@houston.rr.com (Skywise)
wrote:
//这里是加载HEADER数据的代码! !!!
string Temp;
fin.getline(Temp,255); //问题行
};
// HERE IS THE CODE LOADING THE HEADER DATA!!!!
string Temp;
fin.getline(Temp,255); // PROBLEM LINE
};




这是什么;做在别的结尾?它不应该是

那里。



What is that ; doing at the end of an else? Its not suppose to be
there.


Skywise写道:
Skywise wrote:


/ /这是加载标题数据的代码!!!!
string Temp;
fin.getline(Temp,255); //问题行


// HERE IS THE CODE LOADING THE HEADER DATA!!!!
string Temp;
fin.getline(Temp,255); // PROBLEM LINE




你不能像这样使用getline的字符串变量。

对于使用字符串,有一个独立的getline函数,

做你想要的。


getline(fin,Temp);

(我知道,我知道。字符串'' s与其他

标准课程没有尽可能好。)

-

Karl Heinz Buchegger kb******@gascad.at


zalzon写道:

2004年8月23日20:04:36 -0700, th ******** @ houston.rr.com (Skywise)
写道:

On 23 Aug 2004 20:04:36 -0700, th********@houston.rr.com (Skywise)
wrote:
//这里的代码是加载的HEADER DATA !!!!
string Temp;
fin.getline(Temp,255); //问题行
};
// HERE IS THE CODE LOADING THE HEADER DATA!!!!
string Temp;
fin.getline(Temp,255); // PROBLEM LINE
};



那是什么;做在别的结尾?它不应该是
那里。



What is that ; doing at the end of an else? Its not suppose to be
there.




但这不是错误。

if-then-else之后是一个空的陈述。

完全合法。


-

Karl Heinz Buchegger
kb ****** @ gascad.at


这篇关于Beginers关于Getline的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆