我的問題涉及使用std::count
(或其他適當的函數)來計算空格分隔文件的列。計算空格分隔文件的列
我目前使用的是這樣的:
std::ifstream inFile("file");
int lines = std::count(std::istreambuf_iterator<char>(inFile),
std::istreambuf_iterator<char>(), '\n');
計數線。
由於所有的線是相等的(相同的數據量),會像
std::ifstream inFile("file");
int columns = std::count(std::istreambuf_iterator<char>(inFile),
std::istreambuf_iterator<char>('\n'), ' ') + 1;
做什麼,我需要什麼?
感謝
編輯:
我的意思是,如果在"file"
有像1 2
或1 [many spaces here] 2
數據,會的columns
值反正是2或不是?
爲什麼不嘗試呢? –
@Ed:因爲我只有一臺機器,目前正在忙於大量計算,與此同時我正在考慮如何解決這個問題。 – Federico