In the below program i have inputted multiple string inputs like in the example below. Now i want to assign the multiple lines parsed data into different variables of different type.
int main()
{
int line=3, t;
string s, bigString;
for(int i=0 ; i<line ; i++)
{
getline(cin,s);
bigString += s + "\n";
}
cout <<bigString <<endl;
return 0;
}
Sample Input:
1 toy at 10.65
2 box of books at 12.11
1 pot plant at 6.45
I would like to parse and assign my variables like below,
//For storing array of variables,
int quantity;
Map<string,double>itemAndPrice;
ex1:
quantity = 1
itemAndPrice.first() = toy;
itemAndPrice.second() = 10.65;
ex2:
quantity = 2
itemAndPrice.first() = box of
books;
itemAndPrice.second() = 12.11;
ex3:
quantity = 1
itemAndPrice.first() = pot plant;
itemAndPrice.second() = 6.45;
As every input is different, how to parse and assign in respective variables in a generic way.