从txt文本中读取数据存入数组中

  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <vector>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. ifstream infile;
  10. infile.open("1.txt");
  11. if(!infile) cout<<"error"<<endl;
  12.  
  13. string str;
  14. int t1;
  15. /* while(getline(infile,str)) //按行读取,遇到换行符结束
  16. {
  17. infile.getline(str,10);
  18. cout<<str<<endl;
  19. }
  20. */
  21. /*//存入vector
  22. cout<<"存入vector"<<endl;
  23. vector<int> ve;
  24. while(infile>>t1) //按空格读取,遇到空白符结束
  25. {
  26. ve.push_back(t1);
  27. }
  28.  
  29. for(int i=0;i<ve.size();i++)
  30. cout<<ve[i]<<" ";
  31. cout<<endl;
  32. */
  33.  
  34. //存入数组
  35. cout<<"存入数组"<<endl;
  36. int a[][];
  37. int*p=&a[][];
  38. while(infile>>t1) //遇到空白符结束
  39. {
  40. *p=t1;
  41. p++;
  42. }
  43. infile.close();
  44. for(int i=;i<;i++)
  45. { for(int j=;j<;j++)
  46. cout<<a[i][j]<<"\t";
  47. cout<<endl;
  48. }
  49. return ;
  50. }

参考博文:https://www.cnblogs.com/helinsen/archive/2012/07/26/2609251.html

http://blog.csdn.net/u010220351/article/details/52347631

c++从文件中读取一行数据并保存在数组中的更多相关文章

  1. python中读取mongodb数据并保存为csv格式的文件

    import pandas as pd import matplotlib.pyplot as plt import pymongo %matplotlib inline # 连接mongodb数据库 ...

  2. Java输入一行数据并转存到数组中

    直接看下面的代码吧!主要是split和foreach的使用 import java.io.*; import java.util.*; public class Main{ public static ...

  3. matlab中读取txt数据文件(txt文本文档)

    matlab中读取txt数据文件(txt文本文档) 根据txt文档不同种类介绍不同的读取数据方法 一.纯数据文件(没有字母和中文,纯数字) 对于这种txt文档,从matalb中读取就简单多了 例如te ...

  4. C 语言实例 - 从文件中读取一行

    C 语言实例 - 从文件中读取一行 从文件中读取一行. 文件 runoob.txt 内容: $ cat runoob.txt runoob.com google.com 实例 #include < ...

  5. C# 操作地址 从内存中读取写入数据(初级)

    本示例以植物大战僵尸为例, 实现功能为 每1秒让阳光刷新为 9999.本示例使用的游戏版本为 [植物大战僵尸2010年度版], 使用的辅助查看内存地址的工具是  CE. 由于每次启动游戏, 游戏中阳光 ...

  6. python 读取SQLServer数据插入到MongoDB数据库中

    # -*- coding: utf-8 -*-import pyodbcimport osimport csvimport pymongofrom pymongo import ASCENDING, ...

  7. JAVA反射机制示例,读取excel数据映射到JAVA对象中

    import java.beans.PropertyDescriptor; import java.io.File; import java.io.FileInputStream; import ja ...

  8. 如何实现MySQL表数据随机读取?从mysql表中读取随机数据

    文章转自 http://blog.efbase.org/2006/10/16/244/如何实现MySQL表数据随机读取?从mysql表中读取随机数据?以前在群里讨论过这个问题,比较的有意思.mysql ...

  9. C#中向ListView控件中添加一行数据

    C#中向ListView控件中添加一行数据: ,先声明一个ListViewItem: ListViewItem item = new ListViewItem(); ,添加第一列数据: item.Te ...

随机推荐

  1. android中sharedPreferences的用法(转)

    SharedPreferences介绍:   做软件开发应该都知道,很多软件会有配置文件,里面存放这程序运行当中的各个属性值,由于其配置信息并不多,如果采用数据库来存放并不划算,因为数据库连接跟操作等 ...

  2. DOS 配置IP地址

    @echo off :startIP set /p source=STATIC Y or N or E: echo source:%source% if "%source%" == ...

  3. POJ 3273 Monthly Expense(二分搜索)

    Description Farmer John is an astounding accounting wizard and has realized he might run out of mone ...

  4. SpringBoot(九)-- SpringBoot JDBC

    1.属性配置文件(application.properties) # type 可以修改连接池类型,默认采用Tomcat的连接池 # spring.datasource.type=com.alibab ...

  5. ice服务初探

    http://masterkey.iteye.com/blog/182975 http://blog.csdn.net/moxiaomomo/article/details/6773979 http: ...

  6. linux 信息收集脚本。转自insight-labs

    找出所有.sh .pl .py .conf .cnf .ini .*history .*pass* (/usr/share目录里面的除外) 并且在当前目录zip打包.有些时候很多配置文件的权限配置不严 ...

  7. Maven构建Web项目

    1. Maven的作用: [清理项目]→[编译项目]→[测试项目]→[生成测试报告]→[打包项目]→[部署项目] 2. 安装maven maven对JDK版本有要求,所以要设置好JDK的环境变量. M ...

  8. 手机CPU

    说起手机CPU的历史,笔者给大家提一个问题:"世界上第一款智能手机是什么呢?"相信很多人的答案是爱立信的R380或诺基亚的7650,但都不对,真正的首款智能手机是由摩托罗拉在200 ...

  9. windos或linux中 which命令 查看当前要执行的命令所在的路径

    whereis 用来查看一个命令或者文件所在的绝对路径,而 which 用来查看当前要执行的命令所在的路径. 下面举个例子来说明.加入你的linux系统上装了多个版本的java.如果你直接在命令行敲命 ...

  10. Android设计和开发系列第一篇:Notifications通知(Design)

    Design篇 Notifications The notification system allows users to keep informed about relevant and timel ...