Include Include Include Include Include Include Using Namespace Std Function Prototype Voi Q43898512
怎么了?
#include <iostream>
#include<string>
#include<fstream>
#include<vector>
#include<algorithm>
#include<sstream>
using namespace std;
//Function prototype
void print(vector<string>);
int main()
{
//Creste file read object
ifstream in(“C:/Users/Hao/Desktop/moviesl.txt”);
//Check file present or not
//Otherwise prompt for user
string fName;
//Check file exist
while (!in) {
cout << “File not open!!Try again” << endl;
cout << “Enter file name: “;
cin >> fName;
in.open(fName);
}
//Variables for file operation
string line;
string title;
//Store titles vector
vector<string> titles;
//Loop until end of the file
while (!in.eof()) {
//Read line by line
getline(in, line);
//stream object
stringstream ss(line);
//Get title of the movie
getline(ss, title, ‘,’);
//Push into vector
titles.push_back(title);
}
//Sort alphabetically
sort(titles.begin(), titles.end());
///Call method to print
print(titles);
}
//Function to print movie titles
void print(vector<string> titles) {
for(int i=0;i<titles.size();i++) {
cout << titles.at(i) <<endl;
}
}
123.cpp x #include <iostream> #include<string> #include<fstream> 3 #include<vector> #include<algorithm> #include<sstream> using namespace std; //Function prototype void print (vector<string>); int main () 10 11 Creste file read object 12 ifstream in (“C:/Users/Hag/Desktop/moviesl.txt”): 13 //Check file present or not 14 //Otherwise prompt for user 15 string fName; //Check file exist 16 17 while (!in) { 18 19 cout << “File not open!!Try again” << endl; cout << “Enter file name: 20 “; 21 cin >> fName; in.open (fName) ; 22 23 //Variables for file operation 24 string line; string title; 25 26 //Store titles vector 27 28 vector<string> titles; 29 //Loop until end of the file Awhile (!in.eof ()) { 30 //Read line by line getline (in, line); 31 32 //stream object 33 stringstream ss (line): 34 ogs & others х A CppCheck/Vera++ x A CppCheck/Vera++ messages 1A Code::Blocks O Search results * Build messages x A Ccc Build log XA Csc Сссс х File Line Message === Build file: “no target” in “no project” (compiler: unknown) === In function ‘int main ()’: C:UsersHaoD… error: no matching function for call to ‘std::basic_ifstream<char>::open (std::_cxxll:… _Traits>::open (const char*, std::ios… C:UsersHaoD… 22 C:Program Fil… 595 note: candidate: void std::basic_ifstream_CharT, no known conversion for argument 1 from ‘std::_cxxll::string {aka std:: C:Program Fil… 595 cxxl… note Windows (CR+LF) Line 22, Col 1, Pos 479 Read/Write default C/C++ WINDOWS-936 Insert Show transcribed image text 123.cpp x #include #include #include 3 #include #include #include using namespace std; //Function prototype void print (vector); int main () 10 11 Creste file read object 12 ifstream in (“C:/Users/Hag/Desktop/moviesl.txt”): 13 //Check file present or not 14 //Otherwise prompt for user 15 string fName; //Check file exist 16 17 while (!in) { 18 19 cout
Expert Answer
Answer to 怎么了? #include #include #include #include #include #include using namespace std; //Function prototype void print(…
OR