Answers for "skip headers while reading text"

C++
0

skip headers while reading text

#include<sstream>
...

...
std::ifstream file {"test.txt"};
std::string word, line;
std::istringstream iss;
double var, tab[100][6];
int i=0, j;
...

while(getline(file, line))
{
  if (!(line[0]=='#'))
  {
    iss.str(line);
    
    j = 0;

    while(iss >> var)
    {
      tab[i][j] = var;
      ++j;
    }
    
    iss.clear();

    ++i;
  }
}

file.close();
Posted by: Guest on July-14-2021

Code answers related to "skip headers while reading text"

Browse Popular Code Answers by Language