C++ 读取两个数字但没有空格,RINEX 文件

标签 c++ file-io int double filestream

我正在尝试从 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/

相关文章:

c - c中文本模式和二进制模式的区别

c# - 为什么 Int32 的默认构造函数是无参数的?

c - 尝试在函数中使用 txt 文件时获取 "invalid type argument of ' ->' (have ' int')"

c++ - 一个大池还是几个特定类型的池?

c++ - static_assert 负整数

c++ - 当基类指针指向在基类中声明的派生类虚函数时,为什么会出现编译时错误?

java - 两个(小)数相乘给出负数解,而不是溢出……那为什么呢?

C++ 复制构造函数 : attempting to reference a deleted function

java - 用填充的数据库覆盖您的应用程序数据库

python - 在众多Python文件复制功能中,如果复制被中断,哪些功能是安全的?