Hello
Why isn't this code working:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <fstream.h>
#include <iostream.h>
#include <time.h>
int main()
{
srand((unsigned)time(NULL));
int x=rand()%9;
ofstream value("xvalue.txt", ios::ate, filebuf::sh_write );
if(!value.is_open())
{
cout<<"Could not open file... Error.... Quitting\n";
system("PAUSE");
return 0;
}
value<<"x="<<x<<"; ";
value.close();
char yes;
cout<<"Would you like to view contents of file (up to 200 characters in)?\n y for yes, anything else for quit\n";
cin>>yes;
if (yes=='y' || 'Y')
{
char text[200];
ifstream value_read("xvalue.txt", ios::out | ios::nocreate, filebuf::sh_write);
if(!value_read.is_open())
{
cout<<"error, could not open file\n";
system("PAUSE");
return 0;
}
value_read.getline(text, 200, '\n');
cout<<text[200]; \\this isn't working
system("PAUSE");
value_read.close();
}
return 0;
}
The not working part is it doesn't output the files contents to the screen. And yes, I know there are contents in the file.