This is REALLY starting to bug me. Really.
The folling code, under:
gpp, compiles and removes the tenth integer form a space delimited list of integers in file.txt
Dev-C++, does nothing at all
Turbo, deletes the contents of the file and replaces it with meaningless data.
WHYYYY?????
Is this not ANSI compilant? Anyone????
Code:/* Kth Integer remover This program reads all integers up to and including the Kth, but no more, from a text file called file.txt. It then eliminates the Kth integer. No other numbers are read or otherwise modified. Prerequisite: A space delimited integer file called file.txt exists in the cwd. Note: It may be helpful to, when making the file, make one line of numbers, then another identical line below it. This allows you to better see the removal of the number. */ #include <iostream.h> #include <fstream.h> #include <math.h> //This integer is to be removed from the file, bye bye! #define Kth_integer 10 int lenof(int); int main () { bool stop = false; int b = 0; int inums[Kth_integer]; ifstream ifile("file.txt", ios::in); for (int b = 1; b <= Kth_integer; ++b) { ifile >> inums[b]; } ifile.close(); ofstream ofile("file.txt", ios::in); for (int b = 1; b < Kth_integer; ++b) { ofile << inums[b]; ofile << ' '; } for (int x = 0; x < lenof(inums[Kth_integer]); ++x) { ofile << ' '; } ofile.close(); return 0; } int lenof (int a) { int b = 1; while (a/pow(10, b) >= 1) { ++b; } return b; }



LinkBack URL
About LinkBacks


