I am the newbie of C++.
I want to write a program that can read the file such lik below:
p 6 9
n 3
b 1 6.0
b 1 4.0
b 2 2.0
In such file, I want to read the line with first char b.
I try to use getline() and to judge whether the first char is b.
However, I face the problem is I can easily save the first int, but the second double number I can't save it. I know the reason is I save it in char, so the dobule number are seperated(such like 6.0 become '6' '.' '0').
Thus, does it have other way to save the line with integer and double?
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(){
char b[100];
string word;
int a,d;
double c;
ifstream infile("test.txt");
while(infile){
infile.getline(b,100);
if(b[0] == 'b'){
//where I don't know how to save the data
}
}
}
I'm sorry for my rusty English, but really need your help.
std::istringstream. With it you can use the normal input operator>>.