filelines.cpp

来自「C++&datastructure书籍源码,以前外教提供现在与大家共享」· C++ 代码 · 共 32 行

CPP
32
字号
#include <iostream>#include <fstream>#include <cstdlib>#include <string>using namespace std;#include "prompt.h"// count # of lines in input fileint main(){    ifstream input;    string s;                              // line entered by user        long  numLines = 0;        long  numChars = 0;	string filename = PromptString("enter name of input file: ");    input.open(filename.c_str());    if (input.fail() )    {   cout << "could not open file " << filename << endl;        exit(1);    }        while (getline(input,s))    {   numLines++;        numChars += s.length();    }    cout << "number of lines = " << numLines         << ", number of characters = " << numChars << endl;    return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?