本文整理匯總了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;
}