c++文件操作
发布时间:2020-12-16 07:18:12 所属栏目:百科 来源:网络整理
导读:#include iostream#include fstream#include algorithm#include string#include vectorusing namespace std;void ex1_xtra2(){ //输入一个文件名称 string file_name; cout "Please enter a file to be opened: (try input.txt or text.txt) "; cin file_nam
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
void ex1_xtra2()
{
//输入一个文件名称
string file_name;
cout << "Please enter a file to be opened: (try input.txt or text.txt) ";
cin >> file_name;
//判断是否为空
if ( ! cin || file_name.empty() )
{
cerr << "oops! unable to read file namen"; return;
}
//建立一个读取的ifile,由于读取 input.txt中的内容
intput.txt Alice Emma has long flowing red hair.
Her Daddy says when the wind blows
through her hair,it looks almost alive,like a fiery bird in flight. A beautiful
fiery bird,he tells her,magical but untamed.
``Daddy,shush,there is no such thing,‘‘ she
tells him,at the same time wanting him to
tell her more. Shyly,she asks,``I mean,Daddy,is there?‘‘
input.txt.sort A Alice Daddy Daddy,Emma Her Shyly,``Daddy,``I a alive,almost asks,at beautiful
bird bird,blows but fiery fiery flight.
flowing hair,hair. has he her her her,him
him,in is is it like long looks magical
mean,more. no red same says she she shush,such tell tells tells the the there there?‘‘
thing,‘‘ through time to untamed. wanting when
wind
c_str()函数返回一个指向正规C字符串的指针常量,内容与本string串相同.? 解决的方法有两种: 1.用c_str()函数,下面详细介绍。 2.包含头文件"string" ? 下面我们进入正题,请出我们的今天的主角 ?c_str() ? ?他是一个函数哦。。。不要忘记了括号。。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |