Advertisement
Guest User

Untitled

a guest
Jul 28th, 2015
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. [jhenry7@hills ~]$ g++ mywc.cpp -o mywc
  2. mywc.cpp: In function ‘int num_lines(std::string)’:
  3. mywc.cpp:36:23: error: no matching function for call to ‘std::basic_ifstream<char>::basic_ifstream(std::string&)’
  4. ifstream ifs(filename);
  5. ^
  6. mywc.cpp:36:23: note: candidates are:
  7. In file included from mywc.cpp:9:0:
  8. /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]
  9. basic_ifstream(const char* __s, ios_base::openmode __mode = ios_base::in)
  10. ^
  11. /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*’
  12. /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>]
  13. basic_ifstream() : __istream_type(), _M_filebuf()
  14. ^
  15. /opt/gcc4.9.1/include/c++/4.9.1/fstream:456:7: note: candidate expects 0 arguments, 1 provided
  16. /opt/gcc4.9.1/include/c++/4.9.1/fstream:430:11: note: std::basic_ifstream<char>::basic_ifstream(const std::basic_ifstream<char>&)
  17. class basic_ifstream : public basic_istream<_CharT, _Traits>
  18. ^
  19. /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>&’
  20. mywc.cpp:39:26: error: ‘line’ was not declared in this scope
  21. while (getline(ifs,line))
  22.  
  23. the code that works is
  24.  
  25. int main(int argc,char **argv)
  26. {
  27. argcheck(argc);
  28. string line;
  29. ifstream ifs(argv[1]);
  30. int num_l(0);
  31. if (ifs.is_open())
  32. {
  33. while (getline(ifs,line))
  34. {
  35. cout << line << ++num_l << endl;
  36. }
  37. }
  38. else
  39. {
  40. die("Unable to open");
  41. ifs.close();
  42. }
  43. return (0);
  44. }
  45.  
  46.  
  47.  
  48. i want to put the action here into a function,
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement