Objective Text file analysis. Reading in files, storing information about each f
ID: 3533684 • Letter: O
Question
Objective
Text file analysis. Reading in files, storing information about each file, outputting that information.
Details
Create a struct called fileInfo_t which will hold these fields:
In main, create a vector called vFileInfo to hold a list of fileInfo_t.
Repeatedly prompt the user for full paths of file names until a "." is entered as the file name. If the file cannot be opened, output an error message to the user. And, of course, do not add that file to your vector of file information.
As each full path is entered by the user, create a fileInfo_t object. Populate its fields (fullPath, vContents, charCount).
After that, use the vector push_back function to add that fileInfo_t object to the vFileInfo vector.
After all the files have been analyzed, output the information of each file. Sample screen interaction:
Enter file path: c: emplintstones.txt
Enter file path: c: emp estt.txt
Unable to open 'c: emp estt.txt'
Enter file path: c: emp est.txt
Enter file path: c: emp est2.txt
Enter file path: .
File: c: emplintstones.txt
Char Count: 43
Contents:
fred flinstone
wilma flintstone
barney rubble
File: c: emp est.txt
Char Count: 63
Contents:
Now is the time for
all good men to
come to the aid of
their party
File: c: emp est2.txt
Char Count: 42
Contents:
the quick brown fox
jumps over the lazy dog
Press any key to continue . . .
In the drop box, you only need to upload your .cpp file. DO NOT upload sample .txt files. I will be using my own text files to run against your program.
NOTES (Read all of them, please.)
Explanation / Answer
#iclude<iostream.h>
#include<conio.h>
#include<fstream.h>
void main()
{
fstream file, file1,file2,file3;
file.open("c: emplintstones.txt",ios::in);
file1.open("c: emp estt.txt",ios,in);
file2.open("c: emp est.txt",ios::in);
file3.open("c: emp est2.txt",ios::in);
int ch=0;
char a;
while(file!=eof)
{
if(file.read((*ch)&a,sizeof(a)))
ch++;
}
cout<<"no of character in c: emplintstones.txt is "<<ch;
ch=0;
while(file1!=eof)
{
if(file1.read((*ch)&a,sizeof(a)))
ch++;
}
cout<<"no of character in c: emp estt.txt is "<<ch;
ch=0;
while(file2!=eof)
{
if(file.read((*ch)&a,sizeof(a)))
ch++;
}
cout<<"no of character in c: emp est.txt is "<<ch;
ch=0;
while(file3!=eof)
{
if(file.read((*ch)&a,sizeof(a)))
ch++;
}
cout<<"no of character in c: emp est2.txt is "<<ch;
ch=0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.