It looks pretty good. A couple of points:
1. You don't need to print the newline separately.
Code:
So this:
  fprintf (pFile, "%s %d", "X =", 001);
  fprintf (pFile, "\n");
Can be this:
  fprintf (pFile, "%s %d\n", "X =", 001);
2. You don't need to read the numbers into the variable i and then transfer them to x, y, and z.
You can read them directly into x, y, and z like this:
Code:
fscanf (pFile, "%s = %d", str, &x);
fscanf (pFile, "%s = %d", str, &y);
fscanf (pFile, "%s = %d", str, &z);
3. You're mixing C and C++ file access techniques. You should probably stick with one
or the other in the same program. In particular, this code:
Code:
pFile2= fopen ("aplus2.txt", "w+");
ofstream file;
file.open("aplus2.txt");
file<<x<<endl<<y<<endl<<z<<endl;
file.close();
fclose (pFile); // note that you meant pFile2 here!
Should be like this:
Code:
ofstream file;
file.open("aplus2.txt");
file<<x<<endl<<y<<endl<<z<<endl;
file.close();
That is, you either use a FILE* pointer and fopen/fclose,
or you use an ofstream object and obj.open/obj.close.
There's no point in using both.