c++从文件中读取一行数据并保存在数组中
从txt文本中读取数据存入数组中
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std; int main()
{
ifstream infile;
infile.open("1.txt");
if(!infile) cout<<"error"<<endl; string str;
int t1;
/* while(getline(infile,str)) //按行读取,遇到换行符结束
{
infile.getline(str,10);
cout<<str<<endl;
}
*/
/*//存入vector
cout<<"存入vector"<<endl;
vector<int> ve;
while(infile>>t1) //按空格读取,遇到空白符结束
{
ve.push_back(t1);
} for(int i=0;i<ve.size();i++)
cout<<ve[i]<<" ";
cout<<endl;
*/ //存入数组
cout<<"存入数组"<<endl;
int a[][];
int*p=&a[][];
while(infile>>t1) //遇到空白符结束
{
*p=t1;
p++;
}
infile.close();
for(int i=;i<;i++)
{ for(int j=;j<;j++)
cout<<a[i][j]<<"\t";
cout<<endl;
}
return ;
}
参考博文:https://www.cnblogs.com/helinsen/archive/2012/07/26/2609251.html
http://blog.csdn.net/u010220351/article/details/52347631
c++从文件中读取一行数据并保存在数组中的更多相关文章
- python中读取mongodb数据并保存为csv格式的文件
import pandas as pd import matplotlib.pyplot as plt import pymongo %matplotlib inline # 连接mongodb数据库 ...
- Java输入一行数据并转存到数组中
直接看下面的代码吧!主要是split和foreach的使用 import java.io.*; import java.util.*; public class Main{ public static ...
- matlab中读取txt数据文件(txt文本文档)
matlab中读取txt数据文件(txt文本文档) 根据txt文档不同种类介绍不同的读取数据方法 一.纯数据文件(没有字母和中文,纯数字) 对于这种txt文档,从matalb中读取就简单多了 例如te ...
- C 语言实例 - 从文件中读取一行
C 语言实例 - 从文件中读取一行 从文件中读取一行. 文件 runoob.txt 内容: $ cat runoob.txt runoob.com google.com 实例 #include < ...
- C# 操作地址 从内存中读取写入数据(初级)
本示例以植物大战僵尸为例, 实现功能为 每1秒让阳光刷新为 9999.本示例使用的游戏版本为 [植物大战僵尸2010年度版], 使用的辅助查看内存地址的工具是 CE. 由于每次启动游戏, 游戏中阳光 ...
- python 读取SQLServer数据插入到MongoDB数据库中
# -*- coding: utf-8 -*-import pyodbcimport osimport csvimport pymongofrom pymongo import ASCENDING, ...
- JAVA反射机制示例,读取excel数据映射到JAVA对象中
import java.beans.PropertyDescriptor; import java.io.File; import java.io.FileInputStream; import ja ...
- 如何实现MySQL表数据随机读取?从mysql表中读取随机数据
文章转自 http://blog.efbase.org/2006/10/16/244/如何实现MySQL表数据随机读取?从mysql表中读取随机数据?以前在群里讨论过这个问题,比较的有意思.mysql ...
- C#中向ListView控件中添加一行数据
C#中向ListView控件中添加一行数据: ,先声明一个ListViewItem: ListViewItem item = new ListViewItem(); ,添加第一列数据: item.Te ...
随机推荐
- Java Jdk1.8 HashMap源代码阅读笔记二
三.源代码阅读 3.元素包括containsKey(Object key) /** * Returns <tt>true</tt> if this map contains a ...
- nodejs服务器部署教程三
安装mongodb数据库 如何在ubuntu上安装mongodb数据库,其实官方文档写的很清楚啦 sudo apt-key adv --keyserver hkp://keyserver.ubuntu ...
- mysql性能监控qps,tps,iops
qps 每秒处理的查询数tps 每秒处理的事务数IOPS,每秒磁盘进行的I/O操作次数 给个方法或者思路,用啥工具或者命令,如何看,值是多少属于正常范围之内呢? Information from we ...
- laravel 5.3升级5.4
1)修改 composer 配置文件 composer.json 1.如果你用了 laravel-admin,larvel-admin 版本改 1.4.x-dev 2.laravel 版本改 5.4. ...
- Django 数据传递
在前面的访问数据库中,我们是这样来插入数据的: [root@localhost web]$ cat web/urls.py urlpatterns = patterns('', .... url(r' ...
- apk反编译看包名什么的
首先默认你是装了java环境的 到google code里面下载apktool1.5.2.tar.bz2和apktool-install-windows-r05-ibot.tar.bz2(地址:htt ...
- (转载)Recyclerview | Intent与Bundle在传值上的区别 | 设置布局背景为白色的三种方法
用Recyclerview实现列表分组.下拉刷新以及上拉加载更多 http://www.jianshu.com/p/be62ce21ea57 Intent与Bundle在传值上的区别http://b ...
- js验证checkboxlist是否有选中的项
function Check() { var cbl = document.getElementById("<%= ddlSurveyCompanyName.ClientID %> ...
- 使用VS Code写PHP并进行调试
VS Code(Visual Studio Code)是由微软研发的一款免费.开源的跨平台文本(代码)编辑器. 1.先从官网下载安装好VS Code.官方下载地址是https://code.visua ...
- 清空Cookie
function delCookie() { ; i < cookies.length; i++) { try { document.cookie = cookies[i] + "=0 ...