######这个程序为什么老是打开后就闪退呢?
#######
include<iostream>
using namespace std;
#include<stdio.h>
#include<stdlib.h>
int main()
{
FILE* fp;
char s[100];
if ((fp = fopen("file.TXT", "w")) == NULL)
{
cout << "can not open file\n";
exit(1);
system("pause");
}
fputs("I love my homeland", fp);//the front is a char(can be pointer,too.The latter is the file's position
fclose(fp);
if ((fp = fopen("file1.TXT", "r")) == NULL)
{
cout << "can't not open file\n";
exit(1);
system("pause");
}
fgets(s, 10, fp);//read 9 chars and put them into fp;s is the name of head position
puts(s);
system("pause");
return 0;
}
谢谢!
在结尾处写一个getchar()看看