How can i get and then store a space delimited input in c++ from a user into an array ?
Most important part is that length is unknown and input should be by user during runtime
#include<iostream>
using namespace std;
int main() {
int n=0;
string names[3];
int i = 0;
while ( getline( cin, names[i]))
{
cout<<"i = "<<i<<"\n";
cout<<names[i]<<"\n";
i++;
cout<<"i = "<<i<<"\n";
}
for(i=0;i<3;i++)
{
cout<<names[i];
}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire