求编程问题!!!急~~~

来源:百度知道 编辑:UC知道 时间:2024/05/28 07:06:30
主函数从命令行读出一个文件名,然后调用函数GETLINE从文件中读出一个字符串放到字符数组STR中(字符个数最多为100个)。函数返回字符串的长度。在主函数中输出字符串及其长度。
请编程高手帮忙解答~~谢谢了!!
谢了 可是不行啊打不开 "stdafx.h""fstream.h" #include<iostream.h> 这个文件`

#include "stdafx.h"
#include "fstream.h"
#include<iostream.h>
#include<string.h>
int main()
{
cout<<"输入文件名(带扩展名):";
char name[10];
cin>>name;
fstream cf;
cf.open(name,ios::in|ios::nocreate);
if(!cf)
{cout<<"打开失败";return 0;}
char str[100];
cf.getline(str,100);
cout<<"字符为:"<<str<<endl;
cout<<"长度为"<<strlen(str);
}