VC++ 写入txt

来源:百度知道 编辑:UC知道 时间:2024/07/03 00:17:46
我想要把0;1;34;23;67;54;9;3这8个数写入n.txt的文本中,会的大侠帮忙写一下代码。
注:VC++ win32

方法实在太多了....

举个WIN API的方法

#include <windows.h>
int main()
{
char *sz="0;1;34;23;67;54;9;3";
DWORD dw;
HANDLE hFile=CreateFile("n.txt",GENERIC_WRITE,0,NULL,CREATE_ALWAYS,0,NULL);
WriteFile(hFile,sz,strlen(sz)+1,&dw,NULL);
CloseHandle(hFile);
return 0;
}

#include <stdio.h>
#include <process.h>

FILE *stream;

int main( void )
{

char s[] = "0;1;34;23;67;54;9;3"
//这个很重要哦~
char c = '\n';
fopen_s( &stream, "n.txt", "w" );
fprintf( stream, "%s%c", s, c );

fclose( stream );

}

#include<fstream>
using std::ofstream;

int main()
{
ofstream fout("n.txt");
if(fout.fail())
{return 1;}
fout<<0<<" "<<1<<" "<<34"<<" &