Thanks guys, I figured out a bit different way to do it....now I have another problem...the file has character as well as numbers. The numbers could be anything from ints to floats. I only want to pick out these as I'm reading the file in. I know how to code it in C but I'm not sure how the c++ code would look like.
my c version:
Code:
int main(int argc, char *argv[])
{
int line, con1, con2, i;
char buffer[100];
if (argc != 2)
{
cout << "Commandline Error!";
exit (1);
}
else
{
ifstream examplefile(argv[1]); //open a file indicated by the single command
//line argument
if (! examplefile.is_open())
{
cout << "Error opening file"; exit (1);
}
examplefile.getline (buffer,100);
sscanf(buffer,"%d", &line);
cout << line << endl;
for (i=1; i<=line; i++)
{
examplefile.getline (buffer,100);
sscanf(buffer, "%d, %d", &con1, &con2);
cout << con1 << "," << con2 << endl;
}
return 0;
}
}
this reads decimals only thought.