一、文件输入输出

C/C++

输入:

freopen("in.cpp", "r", stdin);
fclose(stdin);

输出:

freopen("in.cpp", "r", stdout);
fclose(stdout);

C++

输入:

ifstream cin("in.cpp");

cin.close();

输出:

ofstream cout("out.cpp");

cout.close();

二、istringstream ostringstream 和 stringstream.

常用函数:

string str, s;

stringstream str;

stringstring str(s);

str.clear();

str.str(s);

Eg:

#include <sstream>
#include <iostream>
#include <stdio.h>
#include <fstream>
using namespace std; string str, name, pnum;
string outstr; int main() {
ifstream cin("in.cpp");
ofstream cout("out.cpp");
stringstream imess;
stringstream omess;
while (getline(cin, str)){
imess.clear();
omess.str("");
imess.str(str); imess >> name;
omess << name << ":"; while(imess >> pnum) {
omess << " " << pnum;
}
cout << omess.str() << endl;
}
cin.close();
cout.close();
return 0;
}

C++ fstream stringstream的更多相关文章

  1. C++中的IO类(iostream, fstream, stringstream)小结(转)

    原文地址:https://blog.csdn.net/stpeace/article/details/44763009

  2. C++中使用stringstream进行类型转换操作

    stringstream包括istringstream和ostringstream,提供读写string的功能,使用时需包含stream文件.4个操作:1. stringstream strm; 创建 ...

  3. 【c++ Prime 学习笔记】第17章 标准库特殊设施

    17.1 tuple类型 tuple是类似pair的模板: pair和tuple的成员类型都可以不相同 pair恰好有两个成员,tuple可有任意数量的成员 按照不同参数数量和类型实例化出的tuple ...

  4. istringstream、ostringstream、stringstream 类简介

    本文系转载,原文链接:http://www.cnblogs.com/gamesky/archive/2013/01/09/2852356.html ,如有侵权,请联系我:534624117@qq.co ...

  5. [c++][语言语法]stringstream iostream ifstream

    c++中ifstream一次读取整个文件 读取至char*的情况 std::ifstream t; int length; t.open("file.txt"); // open ...

  6. stringstream实例

    stringstream的具体作用稍后来总结,这里分享一个实例,从txt文档中读取数据,并对进行处理. #include <iostream> #include <sstream&g ...

  7. 初识 istringstream、ostringstream、stringstream 运用

    今天编程练习时遇到了istringstream的用法,感觉很实用.后面附题目! C++的输入输出分为三种: (1)基于控制台的I/O (2)基于文件的I/O (3)基于字符串的I/O 1.头文件  # ...

  8. C++ stringstream介绍,使用方法与例子

    From: http://www.usidcbbs.com/read-htm-tid-1898.html C++引入了ostringstream.istringstream.stringstream这 ...

  9. istringstream、ostringstream、stringstream 类介绍 .

    istringstream.ostringstream.stringstream 类介绍 . 转自:http://www.cnblogs.com/gamesky/archive/2013/01/09/ ...

随机推荐

  1. 常用的邮箱服务器(SMTP、POP3)地址、端口

    常用的邮箱服务器(SMTP.POP3)地址.端口 参考网址:http://wenku.baidu.com/link?url=IPv15rPRkd0nsuGH0Dm0A5kFyRaeHJY2_gYpDW ...

  2. 图文解说 Dijkstra.

    Dijkstra 太多文章了,有些简练,有些一笔带过.自己还是花了些时间才明白,刚脆自己写个图文说明的,希望能让还没明白的,尽快清楚. 问题:求某点到图中其他所有点的最短路径(权值和最小) Dijks ...

  3. [转载] 使用异步 I/O 大大提高应用程序的性能

    原文: http://www.ibm.com/developerworks/cn/linux/l-async/ Linux® 中最常用的输入/输出(I/O)模型是同步 I/O.在这个模型中,当请求发出 ...

  4. mysql 聚集函数需要注意的问题

    1.当没有记录的时候,使用聚集函数,会导致出现一条记录,记录的取值都是NULL,如下:mysql> select name from student where name='David';Emp ...

  5. Javascript链式调用案例

    jQuery用的就是链式调用.像一条连接一样调用方法. 链式调用的核心就是return this;,每个方法都返回对象本身. 下面是简单的模拟jQuery的代码, <script> win ...

  6. 算法_栈的Java的通用数组实现

    栈是一个常用的最简单的数据结构,这里提供了其实现.内部维护了一个数组,并且可以动态的调整数组的大小.而且,提供了迭代器支持后进先出的迭代功能.Stack的实现是所有集合类抽象数据类型实现的模板,它将所 ...

  7. ios7适配一些问题以及64位32位

    ios7适配一些问题(http://www.cocoachina.com/ios/20130703/6526.html) 1.iOS应用如何实现64位的支持 http://www.codeceo.co ...

  8. 如何定位摄像机,使物体在屏幕上始终具有相同的像素宽度和高度?(threes)

    from How to position the camera so that the object always has the same pixel width and height on the ...

  9. 转:C 函数调用栈

    第一篇: 转自:http://kingj.iteye.com/blog/1555017 本文转自  http://blog.csdn.net/eno_rez/article/details/21586 ...

  10. python linux 磁盘操作

    #coding:utf-8 ''' __author__ = 'similarface' connection:841196883@qq.com 磁盘操作 ''' import psutil impo ...