求助各位C++的Professor,编写一个简练的C++程序(急需)
来源:百度知道 编辑:UC知道 时间:2024/06/03 21:05:24
Write a program to ask user to enter a filename for reading . Read the lines in the file and display the longest line on the screen with corresponding line number.
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main( ) {
cout << "Please enter the name of the file to be read: ";
string fname;
cin >> fname;
ifstream in( fname.c_str( ) );
if( ! in ) {
cout << "Error: File not found or can't be read.\n";
return 1;
}
string s;
getline( in, s );
string longest = s;
int lineNum = 1;
int line = 2;
while( getline( in, s ) ) {
&nb