עבודה עם טמפלט וקבצים בC++ - עמוד 2 - תכנות - HWzone פורומים
עבור לתוכן
  • צור חשבון

עבודה עם טמפלט וקבצים בC++


SweeT_EviL

Recommended Posts

אני לא מצליח להבין את הREAD הזה.

אני מנסה לקרוא שורה. ממה שראיתי באינטרנט עושים את זה ככה:

CFILE

T Read() const throw(CError)
{
T obj;

if(_file.is_open())
{
_file >> obj;
if(_file.fail())
{
throw CError("error while reading file.");
}
}
else
{
throw CError("error file not open.");
}

return obj;
}

CELEMENT

const fstream& operator>>(const fstream& in, CElement& a)
{
char line[256];

in.getline(line,256,'\n');
a._number = atoi(line);

return in;
}

ואני מקבל את השגיאה הזו על השורה של GETLINE

Error	1	error C2663: 'std::basic_istream<_Elem,_Traits>::getline' : 2 overloads have no legal conversion for 'this' pointer

חשבתי שאולי זה הCHAR[] שאני שולח לGETLINE אבל ממה שאני מסתכל באינטרנט אנשים עושים ככה....

קישור לתוכן
שתף באתרים אחרים

כי אם לא אני מקבל

Error	1	error C2678: binary '>>' : no operator found which takes a left-hand operand of type 'const std::fstream' (or there is no acceptable conversion)

כשאני עושה את זה:

	friend fstream& operator>>(fstream& in, CElement& a);

ואם אני מנסה רק להגדיר את in כCONST הוא צועק לי:

Error	2	error C2440: 'return' : cannot convert from 'const std::fstream' to 'std::fstream &'

קישור לתוכן
שתף באתרים אחרים

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

×
  • צור חדש...