本文整理汇总了C++中Basket::setName方法的典型用法代码示例。如果您正苦于以下问题:C++ Basket::setName方法的具体用法?C++ Basket::setName怎么用?C++ Basket::setName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Basket
的用法示例。
在下文中一共展示了Basket::setName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: deserialize
// Deserializing the basket from the binary file in the already existing basket
// If there is an error, the existing basket is not changed
bool Basket::deserialize(const char* file)
{
Basket d;
cout << "Iniating deserialization." << endl;
std::ifstream myfile(file, std::ios::binary);
if (!myfile)
{
cout << "Error" << endl;
return false;
}
int amountOfE;
myfile.read((char*)&amountOfE, sizeof(amountOfE));
if (!myfile)
{
cout << "Error." << endl;
return false;
}
char buffer[1000];
int basketNameLen=0;
myfile.read((char*)&basketNameLen, sizeof(basketNameLen));
myfile.read((char*)buffer, basketNameLen);
name[basketNameLen] = '\0';
d.setName(buffer);
for (int i = 0; i < amountOfE; i++)
{
double eggSize = 0;
myfile.read((char*)&eggSize, sizeof(eggSize));
int nameSize = 0;
myfile.read((char*)&nameSize, sizeof(nameSize));
myfile.read((char*)buffer, nameSize);
buffer[nameSize] = '\0';
d.addÅgg(Egg(buffer, eggSize));
}
//if all is okay, existing basket = basket we just read from the binary file
*this = d;
myfile.close();
return true;
}