Instead of writing a new istringstream argument, can I add another parameter inside nameStream? I have what I think below, and if this method is elligible, then can I tell the input stream to read in a space or endline to separate the two fullnames?
#include <iostream>
#include <string>
using namespace std;
string lastNameFirst (string fullname){
fullname = "Don Blaheta";
fullname2 = "Julian Dymacek";
istringstream nameStream(fullname, fullname2);
string firstName;
string lastName;
string firstName2;
string lastName2;
nameStream>>firstName>>lastName>>firstName2>>lastName2;
return 0;
}
No, that will not work.
As you can see in the definition of
std::istringstreams constructor, it will not take 2std::stringsas parameter. So, you cannot do in this way.You have to concatenate the 2 strings before and then handover to the constructor.
Please see below some example for illustrating what I was explaining:
In more advanced C++ (starting with C++17) you could use variadic template parameters and fold expresssions to concatenate an arbitary number of names, and then split the parts into a
std::vector. Here we can make use of thestd::vectors range constructor(5) in combination with thestd::istream_iterators constructor.But here you need to learn more . . .