Click here to Skip to main content
15,887,214 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How to read a specified amount bytes from a binary-file with a offset (C++) Pin
Daniel Pfeffer8-Jan-24 9:28
professionalDaniel Pfeffer8-Jan-24 9:28 
Questioncatching a divide-by-zero error Pin
mike74115-Jan-24 6:52
mike74115-Jan-24 6:52 
AnswerRe: catching a divide-by-zero error Pin
Maximilien5-Jan-24 6:54
Maximilien5-Jan-24 6:54 
AnswerRe: catching a divide-by-zero error Pin
jeron15-Jan-24 7:00
jeron15-Jan-24 7:00 
AnswerRe: catching a divide-by-zero error Pin
Greg Utas7-Jan-24 5:45
professionalGreg Utas7-Jan-24 5:45 
AnswerRe: catching a divide-by-zero error Pin
jschell8-Jan-24 5:51
jschell8-Jan-24 5:51 
AnswerRe: catching a divide-by-zero error Pin
Daniel Pfeffer8-Jan-24 9:33
professionalDaniel Pfeffer8-Jan-24 9:33 
Question!file trickiness Pin
mike74114-Jan-24 1:45
mike74114-Jan-24 1:45 
I have the following file code:

C++
#include <iostream>
#include <fstream>
using namespace std;

int main() {

    //add code below this line

    string path = "student/text/readpractice.txt";

    try {
        ifstream file;
        file.open(path); //content of file goes into memory buffer
        if (!file) {
            throw runtime_error("File failed to open.");
        }
        cout << file.rdbuf(); //read the buffered content
        file.close();
    }

    catch (exception& e) {
        cerr << e.what() << endl;
    }

    //add code above this line

    return 0;

}



Can someone help me understand how this line works:

C++
if (!file) {


How can you use the exclamation point operator on what is probably a class?

Is there some type of overloading that has occurred? I looked thru the code, and I couldn't find the ! point being overloaded.

Any ideas?

Thanks.
AnswerRe: !file trickiness Pin
Maximilien4-Jan-24 2:12
Maximilien4-Jan-24 2:12 
GeneralRe: !file trickiness Pin
mike74114-Jan-24 2:41
mike74114-Jan-24 2:41 
Questionoutputting Δέλτα Pin
mike74112-Jan-24 16:34
mike74112-Jan-24 16:34 
AnswerRe: outputting Δέλτα Pin
Dave Kreskowiak2-Jan-24 17:56
mveDave Kreskowiak2-Jan-24 17:56 
Questionsizeof not working Pin
mike74111-Jan-24 1:31
mike74111-Jan-24 1:31 
AnswerRe: sizeof not working Pin
Richard MacCutchan1-Jan-24 2:28
mveRichard MacCutchan1-Jan-24 2:28 
AnswerRe: sizeof not working Pin
jeron12-Jan-24 5:38
jeron12-Jan-24 5:38 
GeneralRe: sizeof not working Pin
jschell2-Jan-24 6:34
jschell2-Jan-24 6:34 
GeneralRe: sizeof not working Pin
jeron12-Jan-24 7:11
jeron12-Jan-24 7:11 
QuestionPlease - explain the C++ code / function Pin
Salvatore Terress28-Dec-23 6:09
Salvatore Terress28-Dec-23 6:09 
AnswerRe: Please - explain the C++ code / function Pin
Graham Breach28-Dec-23 8:59
Graham Breach28-Dec-23 8:59 
GeneralRe: Please - explain the C++ code / function Pin
Salvatore Terress29-Dec-23 2:56
Salvatore Terress29-Dec-23 2:56 
GeneralRe: Please - explain the C++ code / function Pin
Graham Breach29-Dec-23 3:50
Graham Breach29-Dec-23 3:50 
GeneralMessage Closed Pin
31-Dec-23 8:49
Salvatore Terress31-Dec-23 8:49 
GeneralRe: How to pass xterm -e option as variable? Pin
k505431-Dec-23 17:35
mvek505431-Dec-23 17:35 
GeneralRe: How to pass xterm -e option as variable? Pin
jschell1-Jan-24 2:07
jschell1-Jan-24 2:07 
GeneralMessage Closed Pin
1-Jan-24 9:51
Salvatore Terress1-Jan-24 9:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.