I was learning about getline and istringstream and got stuck with this code giving the output "Hello World World" while I was expecting just "Hello World". Can someone tell me why is it printing that and how can it be fixed? Thank you for your help in advance!
#include <iostream>
#include <sstream>
using namespace std;
int main()
{
string a="Hello world",b;
istringstream x(a);
while(x!=nullptr)
{
cout<<x;
getline(x,b,' ');
cout << b<< " ";
}
return 0;
}