I need to read g file like this:
Osdvkjjl 7.1458005606 2.5562589310 10.7851154376
Hasdv 6.8994379944 3.3007138599 10.1549586070
Hvfwa 8.0612423839 2.8263185824 11.0131654338
Ovas 0.7277996403 7.7406838010 6.7174824649
Hksks 1.2914301872 7.8130212490 7.4929000181
Haa 0.5118915302 8.7619959150 6.6098826442
I first read a whole line with the getline function, now I want to split each line, store the front characters in vector<string> ele
, and store the back coordinates in vector<vector<double>> coor
, How should it be done?
This is the code I wrote, I don't know how to proceed.
#include<iostream>
#include<fstream>
#include<string>
#include<cmath>
#include<vector>
void readCoor(int num, std::vector<std::string>& ele, std::vector<std::vector<double>>& coor);
int main()
{
int num=192;
std::vector<std::string> ele;
std::vector<std::vector<double>> coor;
readCoor(num, ele, coor);
return 0;
}
void readCoor(int num, std::vector<std::string>& ele, std::vector<std::vector<double>>& coor)
{
std::string hang;
std::ifstream coor_in("guiji.xyz", std::ios :: in);
getline(coor_in, hang);
getline(coor_in, hang);
for (int i=0;i<num;i++)
{
getline(coor_in, hang);
}
return;
}