I am still trying to come up with a simple solution where i add lines of words to a 2d array so i can pick an array element and display what is in that array
I can read the lines of text and output which words are on which line but i need to store them in an array
I know people are going to say to use vectors but in this occasion i need to use arrays
How do i add the words to a 2D array? I tried a for loop but that didn't work
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
using namespace std;
int main ()
{
//number of rows and cols
string words[4][4];
//read in file
ifstream inFile ("data.txt");
string line;
int linenum = 0;
while (getline (inFile, line))
{
//displayes the linenum
cout << "\nLine #" << linenum << ":" << endl;
linenum++;
//read the line
istringstream linestream(line);
string item;
int itemnum = 0;
//splits on the whitespace
while (getline (linestream, item, ' '))
{
//dsiplay the words
cout << "Item #" << itemnum << ": " << item << endl;
itemnum++;
}
}
return 0;
}