См.
#include<iostream>
#include<fstream>
int main()
{
std::ifstream inputFile1,inputFile2;
std::string inputfileName;
std::cout << "Enter the input filename 1:";
std::cin >> inputfileName;
inputFile1.open(inputfileName.c_str());
if(inputFile1.is_open())
std::cout<<"File 1 Opened"<<std::endl;
inputfileName.clear();
std::cout << "Enter the input filename 2:";
std::cin >> inputfileName;
inputFile2.open(inputfileName.c_str());
if(inputFile2.is_open())
std::cout<<"File 2 Opened"<<std::endl;
return 0;
}
Вывод:
Enter the input filename 1:text1.txt
File 1 Opened
Enter the input filename 2:text2.txt
File 2 Opened
Process returned 0 (0x0) execution time : 11.545 s
Press any key to continue.
отлично работает для меня.
РЕДАКТИРОВАТЬ:
вы не можете использовать строку в case вместо этого попробуйте это,
#include<iostream>
#include<fstream>
int main()
{
char str[3];
std::cin>>str;
if(toupper(str[0])=='C')
{
if(toupper(str[1])!='F')
str[0]='\0';
}
switch(str[0])
{
case 'i': // open files
case 'I': std::cout<<"Open";
break;
case 'c': // close files
case 'C': std::cout<<"close";
break;
case 'r': // read file line by line into array
case 'R': std::cout<<"Read";
break;
}
return 0;
}
и вы закроете inputfiles () должно быть
void closeinputfiles()
{
inputFile1.close();
inputFile2.close();
}