hello all, i have been doing some C++ tutorials and am learning to work with txt files and reading and writing to them. my problem lies in that is it possible to print variables to a txt file? here is the code for a program i am working on
Code:
#include <cstdlib>
#include <iostream>
#include <conio.h> // for getch()
#include <fstream> // for ofstream
using namespace std;
int main()
{
ofstream a_file( "numbers.txt" );
int x;
cout<<"this is a test of my knowledge of using fstream";
for ( x = 0; x < 100; x++); // make x inrement up to 100
a_file << x; // only prints the actual x not the variable??
a_file.close(); // closes file
getch(); // wait for keypress
};
as you could probably gather, the program runs fine but in the txt file it only shows a bunch of numbers, i was wondering is there a special way i can make it print the variable X? or is it even possible? thank you in advance for all the help