I want to design a program that inputs a string with space and output split string and the number of letters, but I don't know what the "word[]" means in "while (!ss.eof()){}". For example, I input "Programming is fun", the result is
Programming
is
fun
Length:18
While I change "word[i]" to word[0] the result is
fun
Lenght:18
word[1] is
fun
Lenght:18
Could someone explain it?
Here is my code:
#include<iostream>
#include<sstream>
using namespace std;
void printStringArray(string word[], int size)
{
for (int i = 0;i < size;i++)
{
cout << word[i] << endl;
}
}
int main()
{
string word[10];
string str;
getline(cin, str);
stringstream ss(str);
int i = 0;
while (!ss.eof())
{
ss >> word[i];//P
i++;
}
printStringArray(word, 3);
cout << "Lenght:" << str.size();
return 0;
}