我不确定它的定义是什么,filenames因为它没有在问题中引用。从您的评论来看string fileNames[NUMTABLES]; filenames = "some text goes here;, 似乎string类似于 a char。为了创建一个fstream对象,我们需要char *从上述定义中传递一个 where ,将其filenames[i]转换为一个简单的对象char,这可能是问题的原因。
为了克服这个问题,请找到一个示例代码,其中定义了一个字符串数组,并且fstream成功创建了对象,没有任何问题。
char filenames[4][32] = {"Just for testing purposes", "This is for stackoverflow", "Just for enabling", "This is nice program"};
fstream in(filenames[2], ios::in);
另一种方法是使用strtok将字符串分解some text goes here为较小的字符串,如some, text, goes,here如下所示
char *newstr = strtok(filenames, " ");
fstream in(newstr, ios::in);