#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
FILE* file = fopen("C:\\Users\\Administrator\\Desktop\\c.txt", "r");
#include <stdio.h>
using namespace std;
int main()
{
FILE* file = fopen("C:\\Users\\Administrator\\Desktop\\c.txt", "r");
char str[11]; //若果你开辟了10个空间,就只能放是10个,多出的会放在其它的地方,但是会内存泄漏。
memset(str, 0, 10); //申请的空间要首先进行初始化,否则会有意向不到错误
//cout << str << endl;
cout << sizeof(str)/sizeof(*str) << endl;
cout <<strlen(str) << endl;
// int a=fscanf(stdin, "%s", str);//从标准输入流中获取数据
int a = fscanf(file, "%s", str);
cout << sizeof(str) / sizeof(*str) << endl;
cout << strlen(str) << endl;
if (a)
{
cout << a << endl;
cout << str << endl;
}
FILE* file2 = fopen("C:\\Users\\Administrator\\Desktop\\d.txt", "w");
fprintf(file2, "name:%s,age:%d", "yujianhui",10);
fclose(file);
fclose(file2);
system("pause");
}
memset(str, 0, 10); //申请的空间要首先进行初始化,否则会有意向不到错误
//cout << str << endl;
cout << sizeof(str)/sizeof(*str) << endl;
cout <<strlen(str) << endl;
// int a=fscanf(stdin, "%s", str);//从标准输入流中获取数据
int a = fscanf(file, "%s", str);
cout << sizeof(str) / sizeof(*str) << endl;
cout << strlen(str) << endl;
if (a)
{
cout << a << endl;
cout << str << endl;
}
FILE* file2 = fopen("C:\\Users\\Administrator\\Desktop\\d.txt", "w");
fprintf(file2, "name:%s,age:%d", "yujianhui",10);
fclose(file);
fclose(file2);
system("pause");
}