<分区>
我正在尝试读取由 argv[1]
命名的文件,但我不知道该怎么做。感觉这很简单,我在编译时得到的错误信息是,
main.cpp: In function ‘void* ReadFile(char**, int&)’:
main.cpp:43:22: error: request for member ‘c_str’ in ‘*(argv + 8u)’, which is of non-class type ‘char*’
make: *** [main.o] Error 1
这是我的代码:
#include "movies.h"
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
void *ReadFile(char*[], int&);
int size;
int main(int argc, char *argv[])
{
char * title[100];
cout << argv[1] << endl;
//strcpy(argv[1],title[100]);
//cout << title << endl;
ReadFile(argv , size);
return 0;
}
void *ReadFile(char * argv[] , int& size)
{
char data;
//char title[50];
//strcpy(title,argv[1]);
//cout << title << endl;
ifstream fin;
fin.open(argv[1].c_str()); //filename
if (fin.good())
{
fin >> data;
cout << data << " ";
while (!fin.eof( ))
{
fin >> data;
cout << data << " ";
}
}
}