读书人

请问C++读写文件方面的有关问题

发布时间: 2012-02-23 22:01:34 作者: rapoo

请教C++读写文件方面的问题
首先我要先读TXT文件,内容为(133,271)(143,275)(153,279)(163,283)(173,287)(183,291)(192,295)(201,299)(210,303)(218,307)(226,311)(233,315)(239,320)(245,324)(249,328)(253,333)(257,337)(259,342)(260,346)(260,351)(259,356)(257,361)(254,366)(250,371)(245,376)(239,381)(232,386)(226,391)(218,396)(211,401)(203,406)(195,412)(187,417)(180,422)(173,427)(166,431).然后写一个TXT文件,格式如下:(下面的数据改成前面的数据)
IN
PU-219 -1671;
PD51 -1644;
PD303 -1565;
PD531 -1441;
PD729 -1277;
PD893 -1078;
PD1017 -850;
PD1096 -599;
PD1123 -329;
PD1096 -59;
PD1017 193;
PD893 421;
PD729 620;
PD531 784;
PD303 908;
PD51 986;
PD-219 1014;
PD-489 986;
PD-741 908;
PD-969 784;
PD-1168 620;
PD-1332 421;
PD-1456 193;
PD-1534 -59;
PD-1562 -329;
PD-1534 -599;
PD-1456 -850;
PD-1332 -1078;
PD-1168 -1277;
PD-969 -1441;
PD-741 -1565;
PD-489 -1644;
PD-219 -1671;
请问用C++如何实现啊

[解决办法]
没看到你这两个文件有啥关系
[解决办法]
实在是没看出来有什么关系?
[解决办法]
FILE *fp;
fp=fopen(...);

[解决办法]

C/C++ code
#include <stdio.h>FILE *stream, *stream2;int main( void ){   int numclosed;   // Open for read (will fail if file "crt_fopen.c" does not exist)   if( (stream  = fopen( "crt_fopen.c", "r" )) == NULL ) // C4996   // Note: fopen is deprecated; consider using fopen_s instead      printf( "The file 'crt_fopen.c' was not opened\n" );   else      printf( "The file 'crt_fopen.c' was opened\n" );   // Open for write    if( (stream2 = fopen( "data2", "w+" )) == NULL ) // C4996      printf( "The file 'data2' was not opened\n" );   else      printf( "The file 'data2' was opened\n" );   // Close stream if it is not NULL    if( stream)   {      if ( fclose( stream ) )      {         printf( "The file 'crt_fopen.c' was not closed\n" );      }   }   // All other files are closed:    numclosed = _fcloseall( );   printf( "Number of files closed by _fcloseall: %u\n", numclosed );} 

读书人网 >C++

热点推荐