- Nov 22, 1999
- 1,000
- 4
- 81
Ok I'm trying to read from text files but for some reason Visual C++ gives me a weird error. This is what I have so far.
#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>
#include <stdlib.h>
void outputLine(int, const char * const, double);
int main()
{
char filename[20];
cout << "Please input the filename ------>";
cin >> filename;
ifstream inDataFile(filename, ios::in);
if( !inDataFile )
{
cerr << "File coud not be found\n";
exit (1);
}
char * data[20];
cout << data;
return 0;
}
I also tried a separate program but it still would not work. Which is the following:
#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <iomanip.h>
#include <fstream.h>
int main()
{
char * token[20];
int index;
char * bufferptr;
char buffer[90];
char filename[25];
ifstream datafile;
cout << "Enter Filename ------>";
scanf("%s",filename);
datafile.open(filename,ios::in);
if(datafile.fail())
datafile.get(buffer,90);
datafile.ignore(80,'\n');
bufferptr = strtok(NULL,","
index = -1;
while(*bufferptr!='\0')
{
index = index + 1;
token[index] = bufferptr;
bufferptr = strtok(NULL,","
}
return 0;
}
Any help will be greatlty appreciated.
Thanks,
Viper-Frag
#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>
#include <stdlib.h>
void outputLine(int, const char * const, double);
int main()
{
char filename[20];
cout << "Please input the filename ------>";
cin >> filename;
ifstream inDataFile(filename, ios::in);
if( !inDataFile )
{
cerr << "File coud not be found\n";
exit (1);
}
char * data[20];
cout << data;
return 0;
}
I also tried a separate program but it still would not work. Which is the following:
#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <iomanip.h>
#include <fstream.h>
int main()
{
char * token[20];
int index;
char * bufferptr;
char buffer[90];
char filename[25];
ifstream datafile;
cout << "Enter Filename ------>";
scanf("%s",filename);
datafile.open(filename,ios::in);
if(datafile.fail())
datafile.get(buffer,90);
datafile.ignore(80,'\n');
bufferptr = strtok(NULL,","
index = -1;
while(*bufferptr!='\0')
{
index = index + 1;
token[index] = bufferptr;
bufferptr = strtok(NULL,","
}
return 0;
}
Any help will be greatlty appreciated.
Thanks,
Viper-Frag