I am trying to insert a string separated by spaces into an array of strings without using vector in C++. For example:
using namespace std;
int main(
#include
#include
#include
#include
using namespace std;
template
void splitString(string (&arr)[N], string str)
{
int n = 0;
istringstream iss(str);
for (auto it = istream_iterator(iss); it != istream_iterator() && n < N; ++it, ++n)
arr[n] = *it;
}
int main()
{
string line = "test one two three.";
string arr[4];
splitString(arr, line);
for (int i = 0; i < 4; i++)
cout << arr[i] << endl;
}