C++ fstream stringstream
2024-09-19 20:20:43
一、文件输入输出
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;
}
最新文章
- 作业八:团队项目——Alpha阶段项目总结
- Git标签和别名管理
- Spring Framework------>;version4.3.5.RELAESE----->;Reference Documentation学习心得----->;使用spring framework的IoC容器功能----->;方法一:使用XML文件定义beans之间的依赖注入关系
- 智能指针 ADO数据库连接
- PHP--正则表达式和样式匹配--小记
- cat主要有三大功能
- word中几个好用的宏代码(立方米上标、关闭样式自动更新、删除无效样式、表格加粗边框、宋体引号)
- SharedPreferences基础
- 猎豹移动(金山网络)2015校园招聘(c++project师)
- Codeforces 432E Square Tiling(结构体+贪婪)
- CoreJavaE10V1P3.5 第3章 Java的基本编程结构-3.5 操作符
- php--php调java接口验签
- MySQL 实现调用外部程序和系统命令
- http 状态表
- 配置非安装版tomcat服务
- Junit的Assert用法
- Swift可向上滑移出界面的欢迎页简单封装
- appium 3-31626 toast识别
- sql server 存储过程解密
- Dubbo---初识