我正在尝试从 RINEX 文件的行中读取多个数字。文件编号类似于:
12345.67890
但是,由于 RINEX 格式,12345.6789 代表一个度量值,而小数点末尾的 0 实际上代表其他东西。我使用的是基本读入方式:
Rinexfile>>double_temp;
然后我得到 double_temp=12345.67890 我想做的事情
Rinexfile>>double_temp>>int_temp;
并且有 double_temp=12345.6789 和 int_temp=0。格式始终相同,即 4 位小数属于 double,然后是 int,我使用的是 VS2010
谢谢
最佳答案
您需要更复杂的方法:
std::string word;
Rinexfile >> word;
std::size_t dot_pos = str.find('.');
if (dot_pos != std::string::npos) {
std::string doublePart = word.substr(0, dot_pos + 1 + 4); // 4 decimals
std::string intPart = word.substr(dot_pos + 1 + 4);
std::istringstream is(doublePart), is2(intPart);
is >> double_temp;
is2 >> int_temp;
}
这会读取单个 std::string
形式的输入并将其分成两部分:doublePart
是一个包含 '.'
符号和后面的 4 个字母。 intPart
是单词的其余部分。构造 std::istringstream
的临时实例以检索值。
注意:可能需要额外的错误处理。
关于C++ 读取两个数字但没有空格,RINEX 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19201312/