Question
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
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started