I/O Stream Example :
//Reads three numbers from the file infile.txt, sums the numbers,
//and writes the sum to the file outfile.txt.
#include <fstream>
using std::ifstream;
using std::ofstream;
using std::endl;
int main( )
{
ifstream inStream;
ofstream outStream;
inStream.open("infile.txt");
outStream.open("outfile.txt");
int first, second, third;
inStream >> first >> second >> third;
outStream << "The sum of the first 3\n"
<< "numbers in infile.txt\n"
<< "is " << (first + second + third)
<< endl;
inStream.close( );
outStream.close( );
return 0;
}
Navid Plus is a Tech blog focusing on Science material that I learn day through my College and job. Most likely, blog posts contain C++ Programming, Security, Networking, and Math. Let's have some fun.
Subscribe to:
Post Comments (Atom)
Digital Design Part 3
4th→ assembler translates it to the machine language. 1.6 [20] <§1.6> Consider two diļ¬erent implementations of the same instru...
-
A statement is an instruction that is executed and typically updates some variable (called a side effect). An expression is something t...
-
Working with String - File - While Loop //NavidPlus.blogspot.com #include <iostream> #include <fstream> #include &l...
No comments:
Post a Comment