#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>
#include <time.h>
using namespace std;
int create_file(char Filename[128]) {
cout << "Creating file " << Filename << endl;
srand(time(NULL));
ifstream theFile;
theFile.open(Filename);
for (int x=0; x < 24; x++) {
double number = (rand() % 10000 + 1);
theFile << "Entry" << x << " " << number;
if (theFile.fail() {
cout << "create_file failed!";
return 1;
}
}
theFile.close();
return 0;
}
void read_file(char Filename[128]) {
cout << "Reading file" << Filename << endl;
ifstream theFile;
theFile.open(Filename);
bool z=1;
while (z) {
string theString;
theFile >> theString;
cout << theString;
if (theFile.fail()) {
z = 0;
}
}
}
int main () {
char Filename[128] = "thefile.txt";
if (create_file(Filename)) {
cout << "create_file returned 1";
}
read_file(Filename);
}
/home/john/examples/src/files.cxx:16: error: no match for ‘operator<<’ in ‘theFile << "Entry"’
Specifically line 16.


Sign In
Create Account

Back to top









