【发布时间】:2016-06-26 14:55:23
【问题描述】:
我必须使用 C++ 编写一个程序,该程序必须从 .txt 文件中读取数据,其中数据是这种形式
DATE TIME DATETIME(Unix time_T 值)MachineID 温度
现在必须取 time_T 值和温度,我需要执行基数排序
这个文件有超过 3,00,000 条记录,每行保存 1 条记录,如上所述,我知道基数排序,但我完全不知道将上述字符串格式拆分为单独的队列(time_T,Temp)。我正在使用以下代码读取文件:
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;
int main() {
ifstream input("demo.txt");
string line;
while (getline(input, line)) {
cout << line << '\n';
}
return 0;
}
更新 输入示例 2016-01-01 00:00:04.039251 1451624404 01948 4.9
【问题讨论】:
-
std::istringstream,operator>> -
请通过在互联网上搜索“stackoverflow c++ 读取空间分隔”来找到您的重复项。另请参阅相关的“stackoverflow c++ 读取文件 csv”,其中“csv”表示逗号分隔值。
-
当询问如何解析输入文件时,请显示输入格式的示例(如果需要,还显示架构)。
-
@RaviMehta 正如@LogicStuff 提到的,
istringstream会很好用。看到这个答案:stackoverflow.com/a/7868998/2951830
标签: c++ queue radix-sort