字符串小写转大写存txt后读出显示

1、从键盘上输入一个字符串, 把该字符串中的小写字母转换为大写字母,输出到文件test.txt中,然后从该文件读出字符串并显示出来。

#include<iostream>
#include<string>
#include<cctype>
#include<algorithm>
#include<fstream>
using namespace std;

void main(){

    string str="";
    cin>>str;

    transform(str.begin(),str.end(),str.begin(),toupper);

    fstream f("c:\\test.txt",ios::out);
    f<<str;
    f.close();
    f.open("c:\\test.txt",ios::in);
    f>>str;

    cout<<"从C根目录test.txt中读出的内容是:"<<str<<endl;
    f.close();
    system("pause");
}


猜你喜欢

转载自blog.csdn.net/huang123307/article/details/9347521