C++ How do I pull out a value in a string and store in a variable?

Like if the user enters "38 F" how do I take out the 38 only and store it in a variable?

so far my program goes like this:

string text;
double temperature;

cout << "Enter temperature: ";
getline(cin, text); // user enters 38 F
temperature = text // store 38 from string into double
The closest that I could get was:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <fstream>
using namespace std;

int main(void)
{
char text[100];
int textout;
cin>>text;
char fileName[30] = "text.txt";
FILE *F = fopen(fileName,"w");
fprintf(F,"%s",text);
fclose(F);
fopen(fileName,"w");
scanf("%i",textout);
fclose(F);
cout<<endl<<textout;
}
Topic archived. No new replies allowed.