#include#include int main() { BFile file("/boot/home/test.txt", B_READ_ONLY); if (file.InitCheck() == B_OK) { std::cout << "File was opened successfully!" << std::endl; } else { std::cerr << "Error opening file." << std::endl; } return 0; }
#includeIn this example, we create a BFile object without specifying a file path or access mode. We then use the SetTo function to set the file path and access mode. If SetTo returns B_OK, we then use InitCheck to determine if the file was opened successfully. If InitCheck returns B_OK, we output a success message. If it returns anything else, we output an error message. This code example also uses the StorageKit package library.#include int main() { BFile file; if (file.SetTo("/boot/home/test.txt", B_READ_ONLY) == B_OK) { if (file.InitCheck() == B_OK) { std::cout << "File was opened successfully!" << std::endl; } else { std::cerr << "Error opening file." << std::endl; } } else { std::cerr << "Error setting file path." << std::endl; } return 0; }