C++ Question Objective To practice reading from files and working with arrays. T
ID: 3677893 • Letter: C
Question
C++ Question
Objective
To practice reading from files and working with arrays.
Tasks
Accompanying this week’s lab is a text file that we will use as input. We want to read all of the email addresses in the input file into a 2-dimensional character array. Once we’ve read in each of the emails (each email will be on its own line in the file and will span a row of the array), we will then extract the username part of the email and store it in another 2-dimensional character array (example: “sample@ku.edu” turns into “sample”). From there, we will output the usernames from the array to the console and to an output file. Because we’re practicing with arrays, make sure the input file is closed before you do any outputting (this will force us to store the info in arrays).
File:
Explanation / Answer
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream fin;
string fileName = "Emailaddresses.txt";
fin.open(fileName.c_str());
//create an empty list
const int MAX_EMAILS = 1000;
int nEmails = 0;
string Email[MAX_EMAILS];
while(!fin.eof())
{
string aEmail;
fin >> aEmail;
fin.ignore(1000,10);
getline(fin,aEmail);
if(aEmail.find("@")!=string::npos)
// true if an @ sign is found.
{
if(aEmail.find(",")!=string::npos)
// true if a comma has been found.
{
}
{
cout
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.