reading string with space

Hello!
I have a question: how can I read some strings that contains spaces and put them in a vector of strings, using the push_back() function?

I have a collection of functions, for example: [multiply_by_forty two, add_by_five]. All I want to do is to store the strings like: multiply_by, add_by in a vector of strings, and the arguments:forty two, five etc in another vector of strings, but with spaces.
The function convert() converts written numbers to numbers (for ex the output of covert("forty two")is 42;)

Here is the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 public:void split() {
	vector < string > s1;
	vector < string > s2;
	int v[5000], final[5000], found[5000];
	cout << "dati input";
	cin >> inp;  
		for (int i = 0; i < n; i++) {
	    string str = functions.at(i);
	    found[i] = str.find_last_of("_");
	    s1.push_back(str.substr(0, found[i]));	//s1=functia
	    s2.push_back(str.substr(found[i] + 1));	//s2=argumentul
     	    v[i] = convert(s2.at(i));	//textul convertit in numere  
 	    if (s1.at(i) == "add")
		final[i] = inp + v[i];
	    if (s1.at(i) == "substract")
		final[i] = inp - v[i];
	    if (s1.at(i) == "multiply_by")
		final[i] = inp * v[i];
	}
	cout << "output-ul este: [ ";
	for (int j = 0; j < n; j++)
	    cout << final[j] << ", ";
    cout<<"]";
    }



Thank you!
Last edited on
Topic archived. No new replies allowed.