Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c++ How to read multi-word lines into an array from a text file using a while loop I have the following text file of names,

c++ How to read multi-word lines into an array from a text file using a while loop

I have the following text file of names, some include last names:

names.txt lusha soares rohan leo klein adrianna ada

And the following program which reads the names into an array:

#include #include #include #include //INCLUDE fstream

using namespace std;

int main() { const int NUM_EMPS = 5; string EMPS[NUM_EMPS]; int i = 0;

ifstream inputFile; inputFile.open("names.txt");

while (i < NUM_EMPS && inputFile >> EMPS[i]) { i++; } inputFile.close();

cout << "Employee names: " << endl; for (i=0;i

My issue is that it isn't reading a full name into one element in the array, only the first names, so when running the program my output looks like this:

Employee names: lusha soares rohan leo klein

How can I fix this so my output instead looks like:

lusha soares rohan leo klein adrianna ada

Any help would be appreciated!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2017 For Windows Web And Database Applications

Authors: Corinne Hoisington

1st Edition

1337102113, 978-1337102117

More Books

Students also viewed these Databases questions

Question

Prepare an electronic rsum.

Answered: 1 week ago

Question

Strengthen your personal presence.

Answered: 1 week ago

Question

Identify the steps to follow in preparing an oral presentation.

Answered: 1 week ago