감동, 마음이 움직이는 것
[c++] count # of row and col in data file 본문
Tips (Utility, Computer Language, and etc.)
[c++] count # of row and col in data file
Struggler J. 2018. 1. 4. 21:13//Read file and gives the number of rows and columns
//<sstream> is needed for istrigstrem
#include <string>
#include <iostream>
#include <sstream>
#include <fstream>
using namespace std;
void Count_row_col(char* fname, int* row, int* col)
{
int N = 0;
ifstream in(fname);
string unused;
string s;
while ( getline(in, unused) )
{
if(N==1) { s=unused; }
++N;
}
*row = N;
istringstream iss(s);
int columns = 0;
while(iss)
{
string subs;
iss >> subs;
if(subs.length())
{
++columns;
}
}
*col = columns;
cout << *row << " " << *col << endl;
}
'Tips (Utility, Computer Language, and etc.)' 카테고리의 다른 글
[python] folder안의 file이름 읽어들이기 (0) | 2018.01.05 |
---|---|
[python] array에서 특정 값을 가지는 위치 반환 np.where(condition) (0) | 2018.01.05 |
[gnuplot] use single colorbar in multiplot (0) | 2018.01.04 |
[LaTex] Multirow 모드에서 linebreak (0) | 2017.12.25 |
[gnuplot] Variable for data column number? column(n) (0) | 2017.12.25 |