I'm calling a separate program, from my program, to handle a unit conversion. I get the return string just fine, but it doesn't split as I expect. I'm trying to split this (slightly edited) output:
50.05551390197077665789 50.60658280925650487347 0.00000000000000000000
into a vector. Instead it splits into "50.05551390197077665789 50.60658280925650487347", "0.00000000000000000000".
I'm using this function to run the other program:
std::string Util::execute_cmd(const char* cmd)
{
std::array<char, 128> cmd_buffer;
std::string result;
std::unique_ptr<FILE, decltype(&_pclose)> pipe(_popen(cmd, "r"), _pclose);
if (!pipe)
{
throw std::runtime_error("popen() failed!");
}
while (fgets(cmd_buffer.data(), cmd_buffer.size(), pipe.get()) != nullptr)
{
result += cmd_buffer.data();
}
return result;
}
And I implement it here:
void convert_dktm2_to_geo_etrs98()
{
std::string dktm2_pos1 = std::to_string(this->dktm2_position.at(0));
std::string dktm2_pos2 = std::to_string(this->dktm2_position.at(1));
std::string cmd = "echo " + dktm2_pos1 + " " + dktm2_pos2 + " | C:\\OSGeo4W64\\bin\\cs2cs epsg:4094 epsg:4258 -f \"%.20f\"";
std::string result = Util::execute_cmd(cmd.c_str());
std::vector<std::string> latlong = Util::separate_data(result, ' ');
}
I can print "result" and get the expected output, so it's calling the other program and getting a return value. My separate_data function has worked on everything else in my program. I even tried two other ways of splitting the string, but I got the same result. Here is my original implementation anyway
std::vector<std::string> Util::separate_data(std::string input, char delimiter)
{
std::vector<std::string> data;
std::stringstream ss(input);
while (ss.good())
{
std::string entry;
getline(ss, entry, delimiter);
data.push_back(entry);
}
return data;
}
My best guess is that the first space isn't actually a space. Which I just confirmed by trying to change all spaces to commas in the string like this:
std::replace(result.begin(), result.end(), ' ', ',');
which returns this:
50.05551479305879780668 50.60658606200054876467,0.00000000000000000000,
I don't know what that character is. If I copy it it becomes a space. Can I run it through something to convert it to a space?