我怎样才能请求用户输入我的程序需要读取的文件名,并使用.out
扩展名输出名称?简单的用户请求输出和输入的文件名
例子:
char fileName[256];
cout << "What is the file name that should be processed?";
cin >> fileName;
inFile.open(fileName);
outFile.open(fileName);
但我需要它来将文件保存为一个filename.out代替了原来的文件类型(即:.TXT)
我已经试过这样:
char fileName[256];
cout << "What is the file name that should be processed?";
cin >> fileName;
inFile.open(fileName.txt);
outFile.open(fileName.out);
但我得到这些错误:
C:\ users \ matt \ documents \ visual studio 2008 \ projects \ dspi \ dspi \ dspi.cpp(41):error C2228:'.txt'的左边必须有class/struct/union 1> type是'char [256]' (42):错误C2228:'.out'的左边必须有class/struct/union 1> type(文件名)是'char [256]'
尝试使用'x.y.z'之类的文件名或者像“abc.def \ xyz \ file.txt”这样的路径进行测试。 – 2010-09-11 22:53:08
这应该是find_last_of,而不是find_first_of :)谢谢你指出我的错误。 – 2010-09-11 22:57:55
谢谢!像魅力一样工作! – MSwezey 2010-09-12 18:58:00