Use numbers and operate with them if they are inside strings

Hi there, im asked to make a simple program that takes two numbers and perform an arithemtic operation, the problem is that i have to store everything in strings, so i have one string with the first number, and a second string with the operator and the second number, i have to show which operation im making and the result in the same line, if i enter a q the program exits, something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# include<iostream>
# include<string>
using namespace std;
int main ()
{
        cout<<"Enter the first number: ";
	string str1,str2;
	cin>>str1;
	float num1,num2,result;
	while(str1!="q" || str1!="Q")
	{
		cout<<"\n\nEnter the operator and the second number: ";
		cin>>str2;
		if(str2=="q" || str2=="Q")
		break;
                /*till here everything was ok, but now the problem
                  is to make the numbers and operator useful and i
                  have no idea of how to do that cause c++ does not cast from 
                  string to float, and that only would be for the numbers 
                */
                num1=(float)str1.substr(0,string::npos);/*wrong!!!, How do i do          it??*/
                num2=(float)str2.substr(1,string::npos);//wrong!!!
                result=num1 operator num2;//how do a use the operator....
		cout<<"\n\n"<<str1<<str2<<"="<<result;
	}
        cin.ignore(cin.rdbuf()->in_avail()+1);
	return 0;
}

So if the program were correct , it would ask for number one, lets say "10" and for the operator and number two, lest say "+10", and then it would show "10+10=20", and keep asking for and operator and a number, applying them on the result of the previous oparation which i didnt include on the code, until a q is entered and the program ends. How do i do it? (use the numbers and an operator that are contained inside a string). And something else, how do i enter a string with spaces, lest say "!!!FIRST BLOOD!!", cuase with std::cin i can only enter single words. Thank u for ur time and patience. Alejandro from Colombia.
1
2
string sLine = "";
getline(cin, sLine);
i guess u are answering my second question, thank u
As for your first. You wanna isolate the numbers and operator.
Convert the numbers using http://www.cplusplus.com/reference/clibrary/cstdlib/atof.html

And do a switch on the operator.
Damn man, i manage to get the numbers, but didnt read what u wrote about the operator, if u dont tell me to do a switch i would never have thought about it, hahaha , thanks, i was trying to use it directly hahaha, what an @ss.
No worries man :)
Topic archived. No new replies allowed.