Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // apple xcode
- // paulogp
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <cstdlib>
- #include <ctime>
- #include <fstream>
- using namespace std;
- int main (int argc, const char * argv[])
- {
- // input
- ifstream the_input_stream ("infile.txt");
- string the_first, the_last;
- if (the_input_stream.is_open())
- {
- while (the_input_stream)
- {
- the_input_stream >> the_first >> the_last;
- cout << the_last << ", " << the_first << endl;
- }
- }
- the_input_stream.close();
- // output
- int the_rand;
- srand ((unsigned)time (0)); // positive rand
- ofstream the_output_stream ("outputfile.txt", ios::trunc); // ios::trunc to NOT append file
- for (int i = 0; i < 1000000; i++)
- {
- the_rand = (rand() % 100) + 1; // random [1, 100]
- the_output_stream << the_rand << endl;
- }
- the_output_stream.close();
- // how may even number are inside the file
- int the_temp;
- int the_even = 0;
- the_input_stream.open ("outputfile.txt");
- while (the_input_stream)
- {
- the_input_stream >> the_temp;
- if ((the_temp % 2) == 0)
- {
- the_even ++;
- }
- }
- the_input_stream.close();
- cout << "pares: " << the_even << endl;
- cout << "done" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement