I used stdio...not a fan of iostream :P. heres a quick solution that you may be in favor of:
Code:
#include <stdio.h>
void main()
{
//initialise our FILE descriptor variable
FILE *f = NULL;
//Our variables
int s1=2;
int p1=3;
int S,P;
//variables for use when opening the file...
int written_S = 0;
int written_P = 0;
//open the file "filename.txt", for reading and writing.
f = fopen("FILENAME.txt","w");
s1+=1;
p1+=1;
S=s1; // S will now equal 3
P=p1; // P will now equal 4
//Lets print our variables, to check what they are,
//the variable-argument %i means integer, and S will be put here
//the same happens to P
printf("s equals %i\n", S); //S equals 3
printf("p equals %i\n", P); // P equals 4
//This prints the two integers.
fprintf(f, "%i%i\n", S,P); //34 will be printed in the file.
fclose(f);
// So now we have written our file, lets reopen it and find what we have written
f = fopen("FILENAME.txt","r");
//lets scan the file for two integers together %1d means SINGLE DIGIT
//store them in written_S, and written_P
fscanf(f,"%1d%1d\n",&written_S, &written_P);
//Lets print the variables we have found
printf("The found variables are: %i and %i!\n", written_S, written_P);
fclose(f);
}