0

I am trying to read a list.txt file with multiple items (as below)

100/1 
111/1
115/2 
116/3 
120/1

through command prompt say program.exe list.txt , so argv[1] will be the txt file list.txt (kept in cwd) Then i need to separate 100/1 into partname="100" and rev_id="1" and run do_something(); similarly with 111/1 into partname="111" and rev_id="1" (in a loop).

The following is my code snippet. it gives a compilation error at ifstream std::ifstream: "inFile has initializer but incomplete type."

Can someone tell me where i am going wrong here.

Thanks a lot !

#include <vector>
#include <string>
#include <sstream>
#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;

int main (int argc, char *argv[])
{

    ifstream inFile (argv[1]);
    string partName;
    while (inFile)
   {
      getline(inFile, partName);
      cout <<endl<< partName << endl;
    std::string str = partName;
    char *cstr = new char[str.length() + 1];
    strcpy(cstr, str.c_str());

 char * partname=(strtok (cstr,"/"));
    char * rev_id = (strtok (NULL,"/"));
    //do something();
     printf(" \n Partname is %s \n",partname);
  printf(" \n Rev_id is %s \n",rev_id);
   }

inFile.close();

  return 0;
}
Cactus
  • 27,075
  • 9
  • 69
  • 149
vipin
  • 43
  • 1
  • 9

1 Answers1

0

Include header <fstream>.

You can find similar posts here. Little googling is enough.

Infile incomplete type error

C++: variable 'std::ifstream ifs' has initializer but incomplete type

Community
  • 1
  • 1
GORa
  • 61
  • 6