1. #include <stdio.h>
  2. #include <iostream>
  3. #include <fstream>
  4. using namespace std;
  5. void main()
  6. { int a,b;
  7. char c;
  8. ofstream fout("test.txt");
  9. fout<<" "<<0<<" "<<1<<" "<<4<<endl;
  10. fout<<" "<<3<<" "<<4<<" "<<'d'<<endl;
  11. ifstream fin("test.txt");
  12. while (!fin.eof())
  13. {
  14. fin>>a>>b>>c;
  15. cout<<a<<" "<<b<<" "<<c<<endl;
  16. }
  17. cin>>a;
  18. }
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <assert.h>
  5. #include <sstream>
  6. using namespace std;
  7. /**
  8. * double转换为string
  9. */
  10. string doubleToString(double d) {
  11. ostringstream os;
  12. if (os << d)
  13. return os.str();
  14. return "invalid conversion";
  15. }
  16. /**
  17. * string转double
  18. */
  19. double stringToDouble(string str) {
  20. istringstream iss(str);
  21. double x;
  22. if (iss >> x)
  23. return x;
  24. return 0.0;
  25. }
  26.  
  27. int main()
  28. {
  29. ofstream o_file;
  30. ifstream i_file;
  31. string out_text;
  32. o_file.open("xie.txt");
  33. i_file.open("xie1.txt");
  34. assert(i_file.is_open()&&o_file.is_open()) ;
  35. while(!i_file.eof()) //while(i_file>>out_text) 也可判断结束
  36. {
  37. //将其输出到字符串中的作用是为了解决将0.000001类型输出时为科学计数法的问题
  38. i_file>>out_text; //必须使用空格隔开
  39. static int i = 0; //其作用为在文件结尾不会出现空的一行
  40. if(i ==0) o_file<<out_text;
  41. else o_file<<endl<< out_text;
  42. i = 1;
  43. cout<<stringToDouble(out_text)<<endl;
  44. cout<<doubleToString(stringToDouble(out_text))<<endl;
  45. }
  46. i_file.close();
  47. o_file.close();
  48. return 0;
  49. }
  1. //xie1.txt
  2. 0.000001
  3. 0.000012
  4. 0.01
  5. 0.000001

c++对文件操作的支持(一)的更多相关文章

  1. vc文件操作汇总—支持wince

    一.判断文件及文件夹是否存在 // 判断文件是否存在 BOOL IsFileExist(const CString& csFile) { DWORD dwAttrib = GetFileAtt ...

  2. c++对文件操作的支持(二)

    #include <stdio.h> #include <iostream> #include <fstream> using namespace std; voi ...

  3. 4 文件操作 支持图片 视频 mp3 文本等

    #文件操作:send_file,支持图片 视频 mp3 文本等@app.route("/img")def img(): return send_file("1.jpg&q ...

  4. go语言文件操作,这期资料比较详细( 欢迎加入go语言群: 218160862 )

    go语言文件操作,这期资料比较详细 欢迎加入go语言群: go语言深圳群 golang深圳 218160862 点击加入 文件操作 func Open(name string) (file *File ...

  5. 解决Mac OS X 系统在home文件夹下面操作不支持的方法

    解决Mac OS X 系统在home文件夹下面操作不支持的方法   最近需要使用Mac OS X 系统尝试安装使用appium程序,安装过程中发现,Mac OS X 系统在home文件夹下面操作不支持 ...

  6. C# ini文件操作【源码下载】

    介绍C#如何对ini文件进行读写操作,C#可以通过调用[kernel32.dll]文件中的 WritePrivateProfileString()和GetPrivateProfileString()函 ...

  7. 【.NET深呼吸】Zip文件操作(1):创建和读取zip文档

    .net的IO操作支持对zip文件的创建.读写和更新.使用起来也比较简单,.net的一向作风,东西都准备好了,至于如何使用,请看着办. 要对zip文件进行操作,主要用到以下三个类: 1.ZipFile ...

  8. Node基础篇(文件操作)

    文件操作 相关模块 Node内核提供了很多与文件操作相关的模块,每个模块都提供了一些最基本的操作API,在NPM中也有社区提供的功能包 fs: 基础的文件操作 API path: 提供和路径相关的操作 ...

  9. 前端学PHP之文件操作

    × 目录 [1]文件类型 [2]文件属性 [3]目录路径[4]目录遍历[5]目录统计[6]目录增删[7]目录复制[8]文件操作[9]文件内容 前面的话 在程序运行时,程序本身和数据一般都存在内存中,当 ...

随机推荐

  1. (原+转)pycharm中使用caffe

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5896446.html 参考网址: http://www.th7.cn/Program/Python/2 ...

  2. No1_4.数组的基本操作_Java学习笔记

    import java.util.Arrays; public class HelloArrayOp { public static void main(String[] args) { // TOD ...

  3. 查找mysql数据库文件的存放位置

    在mysql数据库中,有时候并不是很容易找出mysql数据库文件data的存放位置吗,这时就可以使用mysql自带的命令行工具进行查询. 具体命令如下:show variables like '%da ...

  4. struts2注解驱动 零配置

    一.配置web.xml<filter><filter-name>struts2</filter-name><filter-class>org.apach ...

  5. 学习PrintWriter类 .

    java.io包 1)首先先知道它的八种构造方法,但怎么记住这八种呢?我们都知道PrintWriter是一种过滤流,也叫处理流.也就是能对字节流和字符流进行处理,所以它会有: PrintWriter( ...

  6. 解决ScrollView中嵌套ListView滚动效果冲突问题

    在ScrollView中嵌套使用ListView,ListView只会显示一行到两行的数据.起初我以为是样式的问题,一直在对XML文件的样 式进行尝试性设置,但始终得不到想要的效果.后来在网上查了查, ...

  7. label的for属性与inputde的id元素绑定

    <form> <label for="male">Male</label> <input type="radio" n ...

  8. symfony配置

    1.获取配置的一些变量 在HttpFoundation/Kernel.php 文件里面有函数 getKernelParameters ()可以获取一些配置变量的数组.有需要可以从那里获取. 2.配置s ...

  9. openssl 第一篇

    自从老罗赞助了openssl以及心脏出血事件的新闻,得以了解了openssl.那么什么是openssl呢?下面摘自官网: The OpenSSL Project is a collaborative  ...

  10. mysql 针对单张表的备份与还原

    A.MySQL 备份工具xtrabackup 的安装 . percona 官方xtrabackup 的二进制版本:二进制版本解压就能用了. . 解压xtrabackup & 创建连接 -Lin ...