In my work a txt file is read, among the data in it, there are geographical positions of the vehicles. Due to a problem I am having at the time of reading this file, I want to read this information as the string type, but I need to store the position information as the Coord type. Is it possible to convert a string to Coord?
Error:
error: invalid operands to binary expression ('__istream_type' (aka 'basic_istream<char, std::char_traits<char> >') and 'veins::Coord')
The error is shown when "while ()" reads the "position" variable as type Coord. The way I thought it would be easier would be to get the position as a string and then convert it to the Coord type and store it in chData.position.
Code of the method used:
std::ifstream file;
file.open("chFile.txt");
if(file.is_open()) {
int sector;
int ch;
Coord position;
while (file >> sector >> ch >> position) {
chTableStruct chData;
chData.ch = ch;
chData.position = position;
chTable.insert(std::pair<int,chTableStruct>(sector,chData));
}
file.close();
}
else {
std::cout << "The file chFile.txt cannot be opened! it exists?" << endl;
}
chFile.txt file:
2 20 (401.467,223.4,0)
3 52 (201.446,223.4,0)
1 31 (201.461,623.4,0)