#include <fstream.h>
ifstream infile("raw.dat") ;
ofstream outfile("process.dat") ;
ifstream infile ;
infile.open ("raw.dat") ;
ofstream outfile ;
outfile.open("process.dat") ;
infile >> num ;
outfile << num ;
char ch ;The first method skips white space, the second does not. infile.get() also returns a value of ZERO or non-ZERO.
infile >> ch ;
infile.get(ch) ;
infile.close() ;
outfile.close() ;
infile.open("raw2.dat")
float price[1000] ;This tells the compiler to reserve a contiguous section of the memory, enough for 1000 float variables, and to associate the name "price" with the entire section.
for (int i=0; i<1000; i++) price[i] = 0.0 ;initializes all 1000 of the slots to the value 0.0 through the use of just one for-loop.
53 6.79and if the program statement is:
cin >> i >> price[i] ;then this serves to change price[53] to the value 6.79. If we want our program to make a long series of price changes, we can use C++ code like:
cout << "Give an index and float value: " ; while (cin >> i >> price[i]) { cout << i << " " << price[i] << endl ; cout << "Give an index and float value: " ; }Then all we have to do is input a series like this to get all the price changes made that we desire:
42 9.99 193 18.54 53 11.98 17 5.79 438 0.79