C & C++

C & C++

Made by DeepSource

Found use of deprecated ios_base aliases CXX-W2031

Anti-pattern
Minor

The use of deprecated ios_base aliases such as ios_base::open_mode and ios_base::seek_dir is considered an antipattern because they have been replaced by their non-deprecated equivalents.

This means that they may not be supported by future versions of C++.

For example, ios_base::open_mode has been replaced by std::ios_base::openmode.

Recommended

#include <fstream>
#include <iostream>

int main() {
    std::ofstream myfile;
    myfile.open("example.txt", std::ios_base::app);
    if (myfile.is_open()) {
        myfile << "This is a line.\n";
        myfile.close();
    }
    return 0;
}
#include <fstream>
#include <iostream>

int main() {
    std::ifstream myfile;
    myfile.open("example.txt");
    if (myfile.is_open()) {
        char c;
        while (myfile.get(c)) {
            std::cout << c;
        }
        myfile.seekg(0, std::ios_base::beg);
        while (myfile.get(c)) {
            std::cout << c;
        }
        myfile.close();
    }
    return 0;
}