I have no format, that's why I am asking. The file can contain one SSN just to make it easy. The SSN is 10 numbers without any dashes or whitespaces. For example: 1467439678.
#include <iostream>
#include <fstream>
#include <iomanip>
usingnamespace std;
int main()
{ // Entry Point
// File Input
ifstream fin;
fin.open("Input.txt");
if (!fin.good()) throw"I/O ERROR";
// File Input Info
int SSN;
fin >> SSN;
SSN = SSN % 10000; // Changes value of INT to the number of '0' you input
// For example you have 999 in your file and you input 100... The output will be 99
// File Output
ofstream fout;
fout.open("Report.txt");
if (!fout.good()) throw"I/O ERROR"; // By doing this skips the monitor output and goes directly to File Output
// File Output Info
fout << setfill('*') << setw(10) << SSN << endl; // The setfill and setw just makes it look nice and readable
return 0;
} // End Point
The File Output is "******9874"
I have tried it and it worked. Thanks Modoran for the code, but it was to long.
#include <iostream>
#include <fstream>
#include <iomanip>
usingnamespace std;
int main()
{ // Entry Point
// File Input
ifstream fin;
fin.open("Input.txt");
if (!fin.good()) throw"I/O ERROR";
// File Input Info
int SSN;
// File Output
ofstream fout;
fout.open("Repot.txt");
if (!fout.good()) throw"I/O ERROR";
while(!fin.eof())
{ // DO NOT put DECLARATION STATEMENTS in WHILE loop
// File Input Info
fin >> SSN
// Show Last 4 Digits of SSN
SSN = SSN % 10000;
// File Output Info
fout << setfill('*') << setw(10) << SSN <<endl;
} // While
return 0;
} // End Point
NOTE: NEVER put Declaration Statements in a WHILE loop
Hope this will help you become fast and lazy programmers ^^