CARVIEW |
Select Language
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Wed, 23 Jul 2025 15:33:22 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Location: /reference/fstream/basic_filebuf/open/
HTTP/1.1 200 OK
Server: nginx
Date: Wed, 23 Jul 2025 15:33:23 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
ETag: W/"7d3c-UK+hp16Ue44JyC9RUiKCDwwe1ck"
Content-Encoding: gzip
Opens the file identified by argument filename, associating its content with the file stream buffer object to perform input/output operations on it. The operations allowed and some operating details depend on parameter mode.
If the object is already associated with a file (i.e., it is already open), this function fails.
In case of failure, the file is not open, and a null pointer is returned.
Concurrent access to the same file stream buffer object may introduce data races.
Reference
C library:
- <cassert> (assert.h)
- <cctype> (ctype.h)
- <cerrno> (errno.h)
-
<cfenv> (fenv.h)C++11
- <cfloat> (float.h)
-
<cinttypes> (inttypes.h)C++11
- <ciso646> (iso646.h)
- <climits> (limits.h)
- <clocale> (locale.h)
- <cmath> (math.h)
- <csetjmp> (setjmp.h)
- <csignal> (signal.h)
- <cstdarg> (stdarg.h)
-
<cstdbool> (stdbool.h)C++11
- <cstddef> (stddef.h)
-
<cstdint> (stdint.h)C++11
- <cstdio> (stdio.h)
- <cstdlib> (stdlib.h)
- <cstring> (string.h)
-
<ctgmath> (tgmath.h)C++11
- <ctime> (time.h)
-
<cuchar> (uchar.h)C++11
- <cwchar> (wchar.h)
- <cwctype> (wctype.h)
Containers:
-
<array>C++11
- <deque>
-
<forward_list>C++11
- <list>
- <map>
- <queue>
- <set>
- <stack>
-
<unordered_map>C++11
-
<unordered_set>C++11
- <vector>
-
Input/Output:
Multi-threading:
-
<atomic>C++11
-
<condition_variable>C++11
-
<future>C++11
-
<mutex>C++11
-
<thread>C++11
-
Other:
- <algorithm>
- <bitset>
-
<chrono>C++11
-
<codecvt>C++11
- <complex>
- <exception>
- <functional>
-
<initializer_list>C++11
- <iterator>
- <limits>
- <locale>
- <memory>
- <new>
- <numeric>
-
<random>C++11
-
<ratio>C++11
-
<regex>C++11
- <stdexcept>
- <string>
-
<system_error>C++11
-
<tuple>C++11
-
<type_traits>C++11
-
<typeindex>C++11
- <typeinfo>
- <utility>
- <valarray>
<fstream>
class templates
classes
basic_filebuf
- basic_filebuf::~basic_filebuf
- basic_filebuf::basic_filebuf
public members
protected virtual members
non-member overloads
-
swap (basic_filebuf)C++11
-
public member function
<fstream>
std::basic_filebuf::open
basic_filebuf* open (const char* filename, ios_base::openmode mode);
basic_filebuf* open (const char* filename, ios_base::openmode mode);basic_filebuf* open (const string filename, ios_base::openmode mode);
Open file
If the object is already associated with a file (i.e., it is already open), this function fails.
Parameters
- filename
- String with the name of the file to open.
- mode
- Flags describing the requested input/output mode for the file.
This is an object of the bitmask type ios_base::openmode that consists of a combination of the following constants:
value stands for access ios_base::in input File open for reading, supporting input operations. ios_base::out output File open for writing, supporting output operations. ios_base::binary binary Operations are performed in binary mode rather than text. ios_base::ate at end The put pointer (pptr) starts at the end of the controlled output sequence. ios_base::app append All output operations happen at the end of the file, appending to its existing contents. ios_base::trunc truncate Any contents that existed in the file before it is open are discarded.
|
).
If the mode has both ios_base::trunc and ios_base::app set, the opening operation fails. It also fails if either is set but ios_base::out is not, or if both ios_base::app and ios_base::in are set.
If the mode has both ios_base::trunc and ios_base::app set, the opening operation fails. It also fails if ios_base::trunc is set but ios_base::out is not.
Return Value
The function returnsthis
if successful.In case of failure, the file is not open, and a null pointer is returned.
Example
|
|
Data races
Modifies the basic_filebuf object.Concurrent access to the same file stream buffer object may introduce data races.
Exception safety
Basic guarantee: if an exception is thrown, the file stream buffer is in a valid state.See also
- basic_filebuf::is_open
- Check if file is open (public member function)
- basic_filebuf::close
- Close file (public member function)
Home page | Privacy policy
© cplusplus.com, 2000-2025 - All rights reserved - v3.3.4s
Spotted an error? contact us
© cplusplus.com, 2000-2025 - All rights reserved - v3.3.4s
Spotted an error? contact us