Til det første spørgsmål:
#include <fstream>
#include <iostream>
const char FileName[] = "test.dat";
int main()
{
int Counter = 0;
std::ifstream In(FileName);
if(In)
{
In >> Counter;
In.close();
}
else
std::cout << "Failed to open " << FileName << std::endl;
Counter++;
std::cout << "Counter is now: " << Counter << std::endl;
std::ofstream Out(FileName);
if(Out)
{
Out << Counter;
Out.close();
}
else
std::cout << "Failed to open " << FileName << " for writing" << std::endl;
}