但我希望一个元素只能写一次,即如果再次形成蒸汽,一旦添加它就不应该再添加。有可能吗?
bool PushandWrite (Water newElement)
{
ifstream in ("F:\\Songs\Water.txt", ios::out|ios::app);
if(i>=5)
{
cout<<"Element cannot be formed"<<endl;
return false;
}
else
{
/Elements[i] = newElement.water;
in>>newElement.Elements[i];
//Elements[i] = newElement.water;
for(int i=0; i<5; i++)
{
for (int j=i+1; j<5; j++)
{
if (Elements[i] == Elements [j])
{
return false;
}
else
return true;
}
}
}
}
void write2file (Water newElement)
{
ofstream out ("F:\\Songs\Water.txt", ios::out|ios::app);
{
if (PushandWrite (newElement))
{
out << newElement.water<<endl;
}
}
}