如果用VC的话:CFile f;
CFileException e;
char* pFileName = "test.dat";
if( !f.Open( pFileName, CFile::modeCreate | CFile::modeWrite | CFile::typeBinary , &e ) )
{
#ifdef _DEBUG
afxDump << "File could not be opened " << e.m_cause << "\n";
#endif
}如果用TC的话:FILE *fp;
int result;/* Set "stdin" to have binary mode: */
result = _setmode( _fileno( stdin ), _O_BINARY );
if( result == -1 )
perror( "Cannot set mode" );
else
printf( "'stdin' successfully changed to binary mode\n" );/* Open for write */
if( (fp= fopen( "data", "w+" )) == NULL )
printf( "The file 'data' was not opened\n" );
else
printf( "The file 'data' was opened\n" );
CFileException e;
char* pFileName = "test.dat";
if( !f.Open( pFileName, CFile::modeCreate | CFile::modeWrite | CFile::typeBinary , &e ) )
{
#ifdef _DEBUG
afxDump << "File could not be opened " << e.m_cause << "\n";
#endif
}如果用TC的话:FILE *fp;
int result;/* Set "stdin" to have binary mode: */
result = _setmode( _fileno( stdin ), _O_BINARY );
if( result == -1 )
perror( "Cannot set mode" );
else
printf( "'stdin' successfully changed to binary mode\n" );/* Open for write */
if( (fp= fopen( "data", "w+" )) == NULL )
printf( "The file 'data' was not opened\n" );
else
printf( "The file 'data' was opened\n" );
有直接COPY的代码!我在网吧,没带
在window下用内存映射,管道传输要好的多,且写的代码并不多。
文件方式适用后者,前者最好用socket