Nov 5, 2014 at 11:23am UTC
Alright, so I don't really know how to explain this, so I'll do my best; I want the user to write some words separated by a comma and a space, and then I want to create a variable for each word, how do I do that? Using getline?
Should I keep the values in a vector, an array or just as separate value? Thanks!
Last edited on Nov 5, 2014 at 11:23am UTC
Nov 5, 2014 at 1:05pm UTC
It was just meant to give you a hint.
Here's another bigger hint :)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#include<iostream>
#include<vector>
#include<sstream>
using namespace std;
int main()
{
std::string line("This,is,my,line,antelope,again" );
std::stringstream lineStream(line);
std::string cell("" );
// collect all the strings
std::vector<std::string> result;
while (std::getline(lineStream, cell, ',' ))
{
result.push_back(cell);
}
return 0;
}
Should I keep the values in a vector, an array or just as separate value?
I've used a vector, but it really depends what you want to do with these individual strings.
Last edited on Nov 5, 2014 at 1:06pm UTC
Nov 5, 2014 at 1:17pm UTC
Perfect!! I already solved my main problem with this super tip :D
Thank you very much! Hope some day I can learn enough code to stop asking so many questions, and maybe start helping people :)
Have a great day!
Nov 5, 2014 at 1:33pm UTC
No worries.
Asking questions is good :)