Advertisement
Guest User

Untitled

a guest
Feb 13th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <cctype>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. void readFile(string);
  10.  
  11. class info {
  12. public:
  13.  
  14. int rows;
  15. int cols;
  16. vector < string > data;
  17. };
  18.  
  19. int main(int argc, char **argv){
  20.  
  21. string filename1;
  22. filename = argv[1];
  23. readFile(filename);
  24.  
  25. return 0;
  26. }
  27.  
  28. //should read onle line at a time from a file and print it
  29. void readFile(string filename1){
  30. fstream datafile;
  31. datafile.open(filename1);
  32.  
  33. while (!datafile.eof()){
  34. string line;
  35. getline(datafile,line);
  36. cout<<line<<endl;
  37. }
  38.  
  39. datafile.close();
  40. }
  41.  
  42. project2.cpp: In function ‘int main(int, char**)’:
  43. project2.cpp:22:2: error: ‘filename’ was not declared in this scope
  44. filename = argv[1];
  45. ^
  46. project2.cpp: In function ‘void readFile(std::string)’:
  47. project2.cpp:32:25: error: no matching function for call to ‘std::basic_fstream<char>::open(std::string&)’
  48. datafile.open(filename1);
  49. ^
  50. project2.cpp:32:25: note: candidate is:
  51. In file included from project2.cpp:2:0:
  52. /usr/lib/gcc/x86_64-pc-cygwin/4.9.3/include/c++/fstream:889:7: note: void std::basic_fstream<_CharT, _Traits>::open(const char*, std::ios_base::openmode) [with _CharT = char; _Traits = std::char_traits<char>; std::ios_base::openmode = std::_Ios_Openmode]
  53. open(const char* __s,
  54. ^
  55. /usr/lib/gcc/x86_64-pc-cygwin/4.9.3/include/c++/fstream:889:7: note: no known conversion for argument 1 from ‘std::string {aka std::basic_string<char>}’ to ‘const char*’
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement