CARVIEW |
Select Language
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Wed, 23 Jul 2025 04:04:41 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Location: /reference/fstream/basic_fstream/basic_fstream/
HTTP/1.1 200 OK
Server: nginx
Date: Wed, 23 Jul 2025 04:04:42 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
ETag: W/"7c9b-kzoFugZ1Cqsny0mpAfX4bCByZms"
Content-Encoding: gzip
Constructs a basic_fstream object:
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_fstream
- basic_fstream::basic_fstream
public member functions
non-member overloads
-
swap (basic_fstream)C++11
-
- Reference
- <fstream>
- basic_fstream
- basic_fstream
public member function
<fstream>
std::basic_fstream::basic_fstream
default (1) | basic_fstream(); |
---|---|
initialization (2) | explicit basic_fstream (const char* filename, ios_base::openmode mode = ios_base::in | ios_base::out); |
default (1) | basic_fstream(); |
---|---|
initialization (2) | explicit basic_fstream (const char* filename, ios_base::openmode mode = ios_base::in | ios_base::out);explicit basic_fstream (const string& filename, ios_base::openmode mode = ios_base::in | ios_base::out); |
copy (3) | basic_fstream (const basic_fstream&) = delete; |
move (4) | basic_fstream (basic_fstream&& x); |
Construct object
- (1) default constructor
- Constructs a basic_fstream object that is not associated with any file.
Internally, its basic_iostream base constructor is passed a pointer to a newly constructed basic_filebuf object (the internal file stream buffer). - (2) initialization constructor
- Constructs a basic_fstream object, initially associated with the file identified by its first argument (filename), open with the mode specified by mode.
Internally, its basic_iostream base constructor is passed a pointer to a newly constructed basic_filebuf object (the internal file stream buffer). Then, basic_filebuf::open is called with filename and mode as arguments.
If the file cannot be opened, the stream's failbit flag is set. - (3) copy constructor (deleted)
- Deleted (no copy constructor).
- (4) move constructor
- Acquires the contents of x.
First, the function move-constructs both its base basic_iostream class from x and a basic_filebuf object from x's internal basic_filebuf object, and then associates them by calling member set_rdbuf.
x is left in an unspecified but valid state.
Parameters
- filename
- A string representing the name of the file to be opened.
Specifics about its format and validity depend on the library implementation and running environment. - mode
- Flags describing the requested input/output mode for the file.
This is an object of the bitmask member type openmode that consists of a combination of the following member constants:
member constant stands for access in input File open for reading: the internal stream buffer supports input operations. out output File open for writing: the internal stream buffer supports output operations. binary binary Operations are performed in binary mode rather than text. ate at end The output position starts at the end of the file. app append All output operations happen at the end of the file, appending to its existing contents. trunc truncate Any contents that existed in the file before it is open are discarded.
|
).
If the mode has both trunc and app set, the opening operation fails. It also fails if either is set but out is not, or if both app and in are set.
If the mode has both trunc and app set, the opening operation fails. It also fails if trunc is set but out is not.
- x
- A basic_fstream object of the same type (with the same class template parameters charT and traits), whose value is moved.
Example
|
|
Data races
The move constructor (4) modifies x.Exception safety
-See also
- basic_fstream::open
- Open 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