Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [jhenry7@hills ~]$ g++ mywc.cpp -o mywc
- mywc.cpp: In function ‘int num_lines(std::string)’:
- mywc.cpp:36:23: error: no matching function for call to ‘std::basic_ifstream<char>::basic_ifstream(std::string&)’
- ifstream ifs(filename);
- ^
- mywc.cpp:36:23: note: candidates are:
- In file included from mywc.cpp:9:0:
- /opt/gcc4.9.1/include/c++/4.9.1/fstream:470:7: note: std::basic_ifstream<_CharT, _Traits>::basic_ifstream(const char*, std::ios_base::openmode) [with _CharT = char; _Traits = std::char_traits<char>; std::ios_base::openmode = std::_Ios_Openmode]
- basic_ifstream(const char* __s, ios_base::openmode __mode = ios_base::in)
- ^
- /opt/gcc4.9.1/include/c++/4.9.1/fstream:470:7: note: no known conversion for argument 1 from ‘std::string {aka std::basic_string<char>}’ to ‘const char*’
- /opt/gcc4.9.1/include/c++/4.9.1/fstream:456:7: note: std::basic_ifstream<_CharT, _Traits>::basic_ifstream() [with _CharT = char; _Traits = std::char_traits<char>]
- basic_ifstream() : __istream_type(), _M_filebuf()
- ^
- /opt/gcc4.9.1/include/c++/4.9.1/fstream:456:7: note: candidate expects 0 arguments, 1 provided
- /opt/gcc4.9.1/include/c++/4.9.1/fstream:430:11: note: std::basic_ifstream<char>::basic_ifstream(const std::basic_ifstream<char>&)
- class basic_ifstream : public basic_istream<_CharT, _Traits>
- ^
- /opt/gcc4.9.1/include/c++/4.9.1/fstream:430:11: note: no known conversion for argument 1 from ‘std::string {aka std::basic_string<char>}’ to ‘const std::basic_ifstream<char>&’
- mywc.cpp:39:26: error: ‘line’ was not declared in this scope
- while (getline(ifs,line))
- the code that works is
- int main(int argc,char **argv)
- {
- argcheck(argc);
- string line;
- ifstream ifs(argv[1]);
- int num_l(0);
- if (ifs.is_open())
- {
- while (getline(ifs,line))
- {
- cout << line << ++num_l << endl;
- }
- }
- else
- {
- die("Unable to open");
- ifs.close();
- }
- return (0);
- }
- i want to put the action here into a function,
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement