C++ 如何让.out文件通过终端键入“读取文本文件”;a、 out<;textfilename.txt";
我是编程新手,我找不到问题的答案 这是我在终端上运行程序时必须打开程序并读取所需文本文件的代码:C++ 如何让.out文件通过终端键入“读取文本文件”;a、 out<;textfilename.txt";,c++,command-line-arguments,C++,Command Line Arguments,我是编程新手,我找不到问题的答案 这是我在终端上运行程序时必须打开程序并读取所需文本文件的代码: using namespace std; int main(int argc, string *argv[]) { string fileName; getline(cin, fileName); ifstream infile(fileName.c_str()); int total[26] = {0}; if (!infile) {
using namespace std;
int main(int argc, string *argv[])
{
string fileName;
getline(cin, fileName);
ifstream infile(fileName.c_str());
int total[26] = {0};
if (!infile)
{
cout << "Error opening file" << endl;
return 0;
}
char b;
while (infile.get(b))
{
if (isalpha(b))
{
b = toupper(b);
int index = b - 'A';
total[index]++;
}
}
使用名称空间std;
int main(int argc,字符串*argv[])
{
字符串文件名;
getline(cin,文件名);
ifstream infle(fileName.c_str());
int-total[26]={0};
如果(!infle)
{
cout当某人使用
while (cin.get(b)) {
// what you've got now...
}