C++ 文件

来源:百度知道 编辑:UC知道 时间:2024/07/07 08:13:43
#include<iostream.h>
#include<fstream>
#include<string.h>
void main()
{
char[100];
unsigned int i;
cout<<"input the string s:\n";
get(s);
ofstream out("file.txt");
if(!out)
{
cout<<"file error!"<<endl;
return;
}
for(i=0;i<strlen(s);i++)
{
if(s[i]>='a' && a[i]<='z')s[i]=s[i]-32;
out.put(s[i]);
}
out.close();
}

查错

要求:大小写转换,从键盘输入字符串s,再定义ofstream流对象与输出文件file.txt建立关联,打开文件后,将s大小写转换,其余字符不变,存放到file.txt文件中

#include<iostream> //用标准c++格式
using namespace std; //用标准c++格式
#include<fstream>
#include<string.h>
void main()
{
char a[100],s[100]; //改过
unsigned int i;
cout<<"input the string s:\n";
gets(s); //gets()
ofstream out("file.txt");
if(!out)
{
cout<<"file error!"<<endl;
return;
}
for(i=0;i<strlen(s);i++)
{
if(s[i]>='a' && a[i]<='z')s[i]=s[i]-32;
out.put(s[i]);
}
out.close();
}

#include<iostream.h>
#include<fstream.h>
#include<string.h>
#include <stdio.h>
void main()
{

char s[100];
unsigned int i;
cout<<"input the string s:\n"<<endl;
gets(s);
ofstream