Get up to 80 % extra points for free! More info:

Discussion: Can anyone help me understand what my errors mean?

In the previous quiz, C++ online test, we tested our experience gained from the course.

Activities
Avatar
JensenBreck
Member
Avatar
JensenBreck:11/30/2017 0:49

Hello,
Below is my code. I am receiving the following errors for this code:

prog5B.cpp: In function ‘int openInfile(std::if­stream&)’:
prog5B.cpp:49: error: no matching function for call to ‘std::basic_if­stream
::open(std::str­ing&)’ /usr/lib/gcc/x86_64-redhat- linux/4.4.7/.­./../../../in­clude/c++/4.4­.7/fstream:525: note: candidates are: void std::basic_if­stream<_CharT, _Traits>::open(con­st char*, std::ios_base::o­penmode) [with _CharT = char, _Traits = std::char_traits] prog5B.cpp:50: error: no matching function for call to ‘std::basic_if­stream >::fail(std::strin­g&)’
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/.­./../../../in­clude/c++/4.4­.7/bits/basic_i­os.h:191: note: candidates are: bool std::basic_ios<_Char­T, _Traits>::fail() const [with _CharT = char, _Traits = std::char_traits]
prog5B.cpp: In function ‘int openOutfile(std::of­stream&)’:
prog5B.cpp:74: error: declaration of ‘std::ofstream outs’ shadows a parameter
prog5B.cpp:75: error: no matching function for call to ‘std::basic_of­stream ::open(std::str­ing&)’ /usr/lib/gcc/x86_64-redhat- linux/4.4.7/.­./../../../in­clude/c++/4.4­.7/fstream:696: note: candidates are: void std::basic_of­stream<_CharT, _Traits>::open(con­st char*, std::ios_base::o­penmode) [with _CharT = char, _Traits = std::char_traits]

Some of this is extremely difficult for me to even understand, but I am mainly confused with the ifstream and ofstream because they are not working for me. Any help is appreciated.
Thanks,
Please help.
Thanks!

I didn't find the right solution from the Internet.

References:http://www.dreamincode.net/…errors-mean/

brand marketing video

 
Reply
11/30/2017 0:49
Avatar
Replies to JensenBreck
Inactive member:12/1/2017 16:01

Hi, I know this output might seem a little bit messy, but actually it' not so difficult to understand. Let me show you, so you know, how to read it a next time.

  1. First separete the output, there are 4 error in total. You know it by the syntax. First there is file e.g. prog5B.cpp, then there is row number or nothing. Where there is nothing, it's header, otherwise it's number of row with error. So that concludes, you have 4 errors on lines 49, 50, 74 and 75.
  2. Back to headers. They represents names of functions in whitch errors occure to make better guidence. For example first 2 errors are in function openInfile() and second 2 in function openOutfile().
  3. That was the easy part, you've probably figured out already, now the harder part, meaning of errors:
    1. prog5B.cpp:49: error: no matching function for call to ‘std::basic_ifstream::open(std::string&)’
      • This is the error, which is telling you, there is not a function with given argument type ifstream.open(string&), which you call on line 49. The second part of the error message even gives you hint, what to do. It's not always right, but this time it's really helpfull.
      • note: candidates are: void std::basic_ifstream<_CharT, _Traits>::open(const char*, std::ios_base::openmode) [with _CharT = char, _Traits = std::char_traits]
      • That means, there exists function ifstream.open(char *), that you had probably meaned to use. And really, when you look in the documentation - http://www.cplusplus.com/…stream/open/ you're going to find it there, even with the example.
    2. prog5B.cpp:50: error: no matching function for call to ‘std::basic_ifstream >::fail(std::string&)’

    3), 4) It's same as 1) and 2), but for the ofstream. Again the documentation can be found - http://www.cplusplus.com/…am/ofstream/

OK, now when error is clear, solution is in place. It's quite easy, you just have to pass right arguments into functions:

  1. Concreatly open() functions don't accept string, but array of chars. You can convert string to one by calling c_str() function on it.
  2. Than fail() functions don't take any argument at all.

I was in a good moode, so I even fixed the code for you and you can find it here. Hoping you bother yourself with reading this long tutorial of mine, on how to read these errors.

Anyway, even if this code now compiles just fine, I assume it won't do, what you want. But I think this is enough for this answer, so if you want futher help, please write here, what the code was supposed to do exactly. Thank you!

Up Reply
12/1/2017 16:01
Inactive user account.
Avatar
Inactive member:12/1/2017 19:14

Sorry, I forgot to add the link for whole source code in the end, so here it is https://www.ict.social/dev-lighter/8

Up Reply
12/1/2017 19:14
Inactive user account.
To maintain the quality of discussion, we only allow registered members to comment. Sign in. If you're new, Sign up, it's free.

3 messages from 3 displayed.