This is the external file my program has to read from //////////////////////////
ID: 3608307 • Letter: T
Question
This is the external file my program has to read from ///////////////////////////////start John Smith 09/11/2004 8884443332 //(intentionally left blank) johnsmith.com //////////////////////////////////end here is the problem.. my array does not recognize the blank,so it takes in the blank as a part of array(i use " getline(fin,a[i]) " a[0]John Smith a[1]09/11/2004 a[2]8884443332 a[3] a[4]johnsmith.com what should I adjust in my program to make it look likethis? a[0]John Smith a[1]09/11/2004 a[2]8884443332 a[3]johnsmith.com This is the external file my program has to read from ///////////////////////////////start John Smith 09/11/2004 8884443332 //(intentionally left blank) johnsmith.com //////////////////////////////////end here is the problem.. my array does not recognize the blank,so it takes in the blank as a part of array(i use " getline(fin,a[i]) " a[0]John Smith a[1]09/11/2004 a[1]09/11/2004 a[2]8884443332 a[2]8884443332 a[3] a[3] a[4]johnsmith.com a[4]johnsmith.com what should I adjust in my program to make it look likethis? a[0]John Smith a[1]09/11/2004 a[2]8884443332 a[3]johnsmith.com a[0]John Smith a[1]09/11/2004 a[1]09/11/2004 a[2]8884443332 a[2]8884443332 a[3]johnsmith.com a[3]johnsmith.comExplanation / Answer
#include<iostream>
#include <fstream>
#include<string>
using namespacestd;
int main(int argc, char*argv[])
{
char ch;
string str;
int count=0,i;
string arr[100];
if(argc!=3) {
}
ifstreamin("input.txt", ios::in | ios::binary|ios::out);
if(!in) {
cout << "Cannot open input file. ";
system("pause");
return 1;
}
while(getline(in,str)>0)
{
if(str.size() !=1)
arr[count++]=str;
cout<<str<<endl;
}
cout<<" nowprinting array "<<endl;
for(i=0;i<count;i++)
cout<<"arr["<<i<<"]"<<arr[i]<<endl;
in.close();
cout<<endl;
system("pause");
return 0;
}
johnsmith.com
now printing array
arr[0]John Smith
arr[1]09/11/2004
arr[2]8884443332
arr[3]johnsmith.com
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.