|
Dieser Artikel wurde maschinell übersetzt. Bewegen Sie den Mauszeiger über die Sätze im Artikel, um den Originaltext anzuzeigen. Weitere Informationen
|
Übersetzung
Original
|
fopen_s, _wfopen_s
errno_t fopen_s( FILE** pFile, const char *filename, const char *mode ); errno_t _wfopen_s( FILE** pFile, const wchar_t *filename, const wchar_t *mode );
|
pFile |
filename |
mode |
|
|
|---|---|---|---|---|
|
NULL |
|
|
EINVAL |
|
|
|
NULL |
|
EINVAL |
|
|
|
|
|
EINVAL |
|
Unicode-Unterstützung
Hinweis
|
|---|
|
|
|
|
|
|
|
|---|---|---|---|
|
UNICODE |
UTF-16LE |
UTF-8 |
UTF-16LE |
|
UTF-8 |
UTF-8 |
UTF-8 |
UTF-16LE |
|
UTF-16LE |
UTF-16LE |
UTF-8 |
UTF-16LE |
|
|
|
|
|
|---|---|---|---|
|
_tfopen_s |
fopen_s |
fopen_s |
_wfopen_s |
|
|
|
|---|---|
|
a |
|
|
a+ |
|
|
r |
_O_RDONLY |
|
r+ |
_O_RDWR |
|
w |
|
|
w+ |
|
|
b |
_O_BINARY |
|
t |
_O_TEXT |
|
c |
|
|
n |
|
|
S |
_O_SEQUENTIAL |
|
R |
_O_RANDOM |
|
T |
_O_SHORTLIVED |
|
D |
_O_TEMPORARY |
|
ccs=UNICODE |
_O_WTEXT |
|
ccs=UTF-8 |
_O_UTF8 |
|
ccs=UTF-16LE |
_O_UTF16 |
|
|
|
|---|---|
|
fopen_s |
|
|
_wfopen_s |
|
Bibliotheken
// crt_fopen_s.c
// This program opens two files. It uses
// fclose to close the first file and
// _fcloseall to close all remaining files.
#include <stdio.h>
FILE *stream, *stream2;
int main( void )
{
errno_t err;
// Open for read (will fail if file "crt_fopen_s.c" does not exist)
err = fopen_s( &stream, "crt_fopen_s.c", "r" );
if( err == 0 )
{
printf( "The file 'crt_fopen_s.c' was opened\n" );
}
else
{
printf( "The file 'crt_fopen_s.c' was not opened\n" );
}
// Open for write
err = fopen_s( &stream2, "data2", "w+" );
if( err == 0 )
{
printf( "The file 'data2' was opened\n" );
}
else
{
printf( "The file 'data2' was not opened\n" );
}
// Close stream if it is not NULL
if( stream )
{
err = fclose( stream );
if ( err == 0 )
{
printf( "The file 'crt_fopen_s.c' was closed\n" );
}
else
{
printf( "The file 'crt_fopen_s.c' was not closed\n" );
}
}
// All other files are closed:
int numclosed = _fcloseall( );
printf( "Number of files closed by _fcloseall: %u\n", numclosed );
}
The file 'crt_fopen_s.c' was opened
The file 'data2' was opened
Number of files closed by _fcloseall: 1
Hinweis