有什么方法可以访问? 有文本文件一样john.txt micheal.txt james.txt ....访问变量的文本文件
我可以用这个代码访问它们:
ifstream file1("james.txt", ios::in);
我可以像打开一个文件?
string name = "james"; ifstream file1(name, ios::in)
有什么方法可以访问? 有文本文件一样john.txt micheal.txt james.txt ....访问变量的文本文件
我可以用这个代码访问它们:
ifstream file1("james.txt", ios::in);
我可以像打开一个文件?
string name = "james"; ifstream file1(name, ios::in)
试试这个:
char name[]="james.txt";
ifstream file1(name, ios::in);
在C++ 03和更早的版本,你需要使用'james.c_str()' ,但原则上,是的。 (在C++ 11中它只会工作。)[我假设你的意思是设置'string name =“james.txt”'。否则,'.txt'将会丢失。] – jogojapan