C++中如何在listview控件窗口读取已储存在磁盘的文件

4 C++中用磁盘文件实现数据输入输出(选修功能)_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
4 C++中用磁盘文件实现数据输入输出(选修功能)
上传于||暂无简介
阅读已结束,如果下载本文需要使用0下载券
想免费下载更多文档?
你可能喜欢评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
第一章 ASP.NET 教程 (基础)
第二章 ASP.NET 教程(高级)C++中vector数组中的数据存入磁盘文件的问题_百度知道
C++中vector数组中的数据存入磁盘文件的问题
&gt.push_back(*temp):;(person &one。.NAME;ostream & operator&lt, id);class person{private。我重载了 啊 ; id, ostream &os){ os &lt.size(); i++) {
fp &&lt!; person * name & i++) {
name[11],char*); 3;#include&
temp = new person(name。;person&gt.ID &vector& vector&lt: char ID[11]。, id),ios_(person &one!(在这里显示没有相匹配的操作符;}; strcpy_s(NAME;}inline person.close();数据!; system(&quot, name):;
stu, sizeof(ID):person(char *name, char *id){ strcpy_s(ID:out);
cin &pause&
char NAME[11], ostream &os);#include&;
friend ostream & operator&&ostream& stu[i];fstream&&&lt, id[11];)!; } for (int i = 0!; i &lt:person(char *;;#include&}int main(){& for (int i = 0。我的目的是要把vector数组中的数据写入到文件中) } fp, sizeof(NAME).txt&iostream&quot。求大师指导.open(&quot!; return 0; i &&lt#include&stu
提问者采纳
&char&&&数据;{&&0;i;(ostream&fstream&&&&i&&&&&&return&&&&#include&&&friend&&stu[i];for&&&os&vector&=&name);}&nbsp,&i++)&ostream&&#include&&ID[11];&&&&&;&&nbsp.push_back(*temp);&*id){&&operator&);inline&&strcpy(NAME;&&new&&&&fp&&(i&name&}int&person(&&i&nbsp,&class&nbsp你这是vs2013编译器吗;&&&{&&0;}(i&&person&=&system(&&*char&&&&nbsp:&nbsp,&&nbsp,person&nbsp:;char&&&nbsp:out).close();namespace&nbsp,ios_base,&0;main(){&id);&for&&strcpy(ID,char*);&&nbsp:;&&&&person&&&nbsp:person(char&=&nbsp.ID&NAME[11];&name[11];&&id[11];&gt.txt&3;id);&&person(char&&person{}&cin&nbsp.open(&&nbsp?我在vs2010 调通#include&vector&int&&&ostream&#include&&}:&iostream&&nbsp.NAME;*name,&&&i++)&char&pause&*;&temp&&&nbsp.size();one)&&{&return&fstream&&using&nbsp
提问者评价
来自团队:
其他类似问题
为您推荐:
其他1条回答
class&&&#include&&char&&&namespace&&ostream&ostream&nbsp.&os)&&这些&;ostream&&&&nbsp.{只看到这;&#include&&nbsp, 没有仔细看你的代码;&person{&operator&&(person&},&一定是&nbsp,&vector&&nbsp?using&&&operator&第一个参数&&NAME[11];&fstream&i#include&&ostream&ostream&nbsp:&&nbsp:&&不是&person(char&&&char&(person&&&&lt,&friend&&重载&iostream&ID[11];为什么是&时;而不能把它们当当作第二个参数, 你先改了 看行不行吧;&&os),char*);//&&&&&&&istream&ostream&&或者&有什么具体原因吗;&&&nbsp,&&*;//&&&amp?&&#include&quot
写过好多次重载了都没注意这个问题 。。。呵呵 谢谢你啊
嘻嘻 下次哪里调试不过了还得问你。。
呵呵, 我的荣幸. 入门级C++各种问题. 都可以叫上我一起研究, 虽然我也不太会, :)
我下次怎么联系你
我的Q: 2D4749EF (16进制)
vector的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁描述如何快速保存ListView内存中大量数据到Excel的WorkSheet。关键之处是使用Range一次存储多行多列数据。实施如果需要将内存中的数据存储到Excel文件中,首先,引用Excel的Com组件。如下图:然后创建Excel应用程序对象appExcel,以及其它的工作簿等。Microsoft.Office.Interop.Excel.Application appE
appExcel = new Microsoft.Office.Interop.Excel.Application();
Workbook workbookD
Worksheet worksheetD
在调用Excel应用程序,或创建Excel工作簿之前,记着加上下面的这段代码:System.Globalization.CultureInfo CurrentCI = System.Threading.Thread.CurrentThread.CurrentC
System.Threading.Thread.CurrentThread.CurrentCulture =
new System.Globalization.CultureInfo("en-US");
这是因为Excel有一个Bug,如果你的操作系统的环境不是英文的,而,Excel是那么就会在下面的代码时,报异常。详细请参考:Excel环境异常解决 接下来就是该创建工作簿,创建一个WorkSheet了。workbookData = appExcel.Workbooks.Add(Missing.Value);
worksheetData = (Worksheet)workbookData.Worksheets.Add(Missing.Value, Missing.Value, Missing.Value, Missing.Value);
worksheetData.Name = "Saved";
存储ListView中的列到WorkSheet的表头:
for (int i = 0; i & listViewData.Columns.C i++)
worksheetData.Cells[1, i+1] = listViewData.Columns[i].T
快速存储ListView中的大量数据上面存储列名时候,你应该看到,是一个Cell一个Cell的存储,这样效率特别低,解决的办法是,使用Rang,一块一块地存储到Excel。R
rangedata = worksheetData.get_Range("A2", Missing.Value);
Range xlRang = null;
int iRowCount = listViewData.Items.C
int iParstedRow = 0, iCurrSize = 0;
int iEachSize = 1000;
int iColumnAccount = listViewData.Columns.C
object[,] objVal = new object[iEachSize, iColumnAccount];
iCurrSize = iEachS
while (iParstedRow & iRowCount)
if ((iRowCount - iParstedRow) & iEachSize)
iCurrSize = iRowCount - iParstedR
for (int i = 0; i & iCurrS i++)
for (int j = 0; j & iColumnA j++)
objVal[i, j] = listViewData.Items[i + iParstedRow].SubItems[j].T
xlRang = worksheetData.get_Range("A" + ((int)(iParstedRow + 2)).ToString(), ((char)('A' + iColumnAccount - 1)).ToString() + ((int)(iParstedRow + iCurrSize + 1)).ToString());
xlRang.Value2 = objV
iParstedRow = iParstedRow + iCurrS
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRang);
xlRang = null;
catch (Exception ex)
MessageBox.Show(ex.Message);
上面的代码,先在内存中声明一个iEachSize×iColumnAccount的数组,iEachSize是每次最大存储的行数,iColumnAccount就是存储的实际列数。然后将ListView中顺序取最大行数的数据,存储到这个矩阵中。接着,在Excel的WorkSheet中,获取对应的Range。需要注意的是,在Excel中,行的索引是从1开始(不像C#,C++中的数组是从0开始的),列的索引是从A开始的,如果有三列,那么就是从A-C。调用Range的Value2属性,把内存中的值赋给Excel就可以了。这样的效率将远远高于一个一个单元存储。提示结束程序之前恢复环境System.Threading.Thread.CurrentThread.CurrentCulture = CurrentCI;
此主题相关图片如下:
阅读(...) 评论()android中对json数据的解析,并在listview中实际,下面是数据_C++
fstream如何读取链表_c语言,指针处理字符串有关问题,__脚本百事通
稍等,加载中……
^_^请注意,有可能下面的2篇文章才是您想要的内容:
android中对json数据的解析,并在listview中实际,下面是数据
fstream如何读取链表
c语言,指针处理字符串有关问题,
android中对json数据的解析,并在listview中实际,下面是数据
android中对json数据的解析,并在listview中现实,下面是数据{"ziparea": "", "enddate": " 00:00:00", "ecertarea": "\u9053\u8def\u8d27\u\u8f93\u9a7e\u9a76\u5458", "ecertstate": "\u4ece\u4e1a", "begindate": " 18:12:30", "sex": "\u7537", "birthday": " 00:00:00", "result": 0, "ecertid": "9000363", "addr": "\u90d1\u5dde\u5e02\u4e2d\u539f\u533a\u4f0f\u725b\u5357\u8def\u79e6\u5cad\u5c0f\u533a4\u53f7\u697c54\u53f7", "name": "\u5b54\u"}
------解决方案--------------------最好先定义一个实体类(A.class)对应数据。
如果你的josn是用默认的josn格式就这样
JosnArray list=JosnArray(“你上面的josn数据”);
List&A& l=new ArrayList&A&();
for(JsonObject o:list)
a=new A();
a.setXXX(o.getString("这里json里面对应的建"))
a.setXXX(o.getString("这里json里面对应的建"))
这样List&A& l里面就装好了数据了直接 A.getxxx()就ok------解决方案--------------------首先 你的json数据还应该加个key如下
{"info":[{"ziparea": "", "enddate": " 00:00:00", "ecertarea": "\u9053\u8def\u8d27\u\u8f93\u9a7e\u9a76\u5458", "ecertstate": "\u4ece\u4e1a", "begindate": " 18:12:30", "sex": "\u7537", "birthday": " 00:00:00", "result": 0, "ecertid": "9000363", "addr": "\u90d1\u5dde\u5e02\u4e2d\u539f\u533a\u4f0f\u725b\u5357\u8def\u79e6\u5cad\u5c0f\u533a4\u53f7\u697c54\u53f7", "name": "\u5b54\u"}]}
接着定义一个entity
public class Info {
private int XX= 0;
private String XXX =
private int XXXX= 0;
public static List&Info& getInfos(String key, String jsonString) {
List&Info& list = new ArrayList&Info&();
JSONObject jsonObject = new JSONObject(jsonString);
// 返回json的数组
JSONArray jsonArray = jsonObject.getJSONArray(key);
for (int i = 0; i & jsonArray.length(); i++) {
JSONObject jsonObject2 = jsonArray.getJSONObject(i);
Info info = new Info();
info .setXX(jsonObject2.getInt("XX"));
info .setXXX(jsonObject2.getString("XXX"));
info .setXXX(jsonObject2.getInt("XXXX"));
list.add(info);
} catch (JSONException e) {
e.printStackTrace();
上面代码中key就为json数据中添加的key
fstream如何读取链表
fstream怎么读取链表?
本人新手,完全菜鸟,望大神们指教 o(∩_∩)o
学生管理系统,想要实现可以保存数据到硬盘
在程序开始的时候读数据。。。。
结尾的时候保存数据。。。。
第一次执行的时候,可以执行
第二次开启,就出现
菜鸟不太懂C++,求指教
------解决方案--------------------1,结构体中不要使用string等不确定长度的字段
2,不要使用ifstream去读取,因为ifstream会把最后一个 结构体 多读一次。------解决方案--------------------1. Student类的next需要在构造函数置0,否则运行时候指不定等于什么,会引起崩溃
2. 把对象保存到文件,或者通过网络传输这种问题是序列化问题(serialization),有很多通用的序列化库,比如boost::serialization,可以google c++ 序列化。
如果只是简单的保存,参考这个#include &iostream&
#include &string&
#include &fstream&
#pragma once
// save基本类型 int,double, float,bool...
template &class Stream, class T&
void serialize(Stream& stream, T& x) {
stream.write((const char*)&x, sizeof(T));
template &class Stream, class T&
void de_serialize(Stream& stream, T& x) {
stream.read((char*)&x, sizeof(T));
template &class Stream, class T&
void serialize(Stream& stream, T* x) {
bool is_not_null_ptr = x != 0;
serialize(stream, is_not_null_ptr);
if(x) {// if x != 0
serialize(stream, *x);
template &class Stream, class T&
void de_serialize(Stream& stream, T*& x) {
bool is_not_null_
de_serialize(stream, is_not_null_ptr);
if(is_not_null_ptr) {
x = new T;
de_serialize(stream, *x);
// std::string
template &class Stream&
void serialize(Stream& stream, const std::string& str) {
int len = str.length();
serialize(stream, len);
stream.write(str.c_str(), len);
template &class Stream&
void serialize(Stream& stream, std::string& str) {
serialize(stream, (const std::string&)str);
// string read
template &class Stream&
void de_serialize(Stream& stream, std::string& str) {
de_serialize(stream, len);
str.resize(len);
for(int i=0; i& i++) {
de_serialize(stream, x);
// 以上部分就是个简单的序列化库了
struct Student {
Student() : next(0) {} // next置0
Student(const string& num, const string& name, double score)
: num(num), name(name), score(score), next(0)
void debug() {
cout && "name: " && name && ", num: " && num
&& ", score: " && score &&
if(next) {
next-&debug();
template&typename Stream&
void serialize(Stream& s, Student& stu) {
serialize(s, stu.num); //保存Student的各属性
serialize(s, stu.name);
serialize(s, stu.score);
serialize(s, stu.next);
template&typename Stream&
void de_serialize(Stream& s, Student& stu) {
de_serialize(s, stu.num);
de_serialize(s, stu.name);
de_serialize(s, stu.score);
de_serialize(s, stu.next);
int main() {
Student s1("111", "s1", 100);
Student s2("222", "s2", 60);
s2.next = &s1; // s2包含s1
ofstream ofs("save.txt", ios::binary);
serialize(ofs, s2);
ofs.close();
Student s3;
ifstream ifs("save.txt", ios::binary);
de_serialize(ifs, s3);
s3.debug();//就是上面s2的内容
c语言,指针处理字符串有关问题,
c语言,指针处理字符串问题,求助。。。。。。。。#include &stdio.h&
#include &string.h&
#include &stdlib.h&
#include &malloc.h&
//将字符串中连续的数字输出为一个数字,并统计数字个数
//比如ser23lkm6345klmo4.w4e'r
&&&&a[0]=23,a[1]=6345,a[2]=4,..........
void main()
char word[100],*p,a[100][10],*
int i = 0,t;
gets(word);
//把字符串中的非数字字符替换成'\0'
while(word[i] != '\0')
if (word[i]&'0' || word[i]&'9')
word[i++] = '\0';
t=i=0;pa = a[0];
{//将连续数字输出
if (*p != '\0' && *(p-1)=='\0')
strcpy(a[i++],p);//这里是不是有问题?调试的时候没有传递值到数组
//检测最后一个'\0'用于终止循环
if (t == strlen(word))
printf("%d",i);
for(;i&=0;i--)
puts(a[i]);
------解决方案--------------------[code=c]
// ArrayT.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include &stdio.h&
#include &string.h&
#include &stdlib.h&
#include &malloc.h&
//将字符串中连续的数字输出为一个数字,并统计数字个数
//比如ser23lkm6345klmo4.w4e'r
&&&&a[0]=23,a[1]=6345,a[2]=4,..........
void main()
char word[100],*p,a[100][10],*
char tmp[100];//临时变量,用于保存没有把word数组中的非字符串替换为'\0'前字符串
int i = 0,t;
int flag = 0;//标识符号,用于判断是否进入下组数字
gets(word);
//把字符串中的非数字字符替换成'\0'
strcpy(tmp,word);
while(word[i] != '\0')
if (word[i]&'0' ------解决方案-------------------- word[i]&'9')
word[i++] = '\0';
t=i=0;pa = a[0];
{//将连续数字输出
if (flag == 0 && *p != '\0' && *(p-1)=='\0')
strcpy(a[i++],p);//这里是不是有问题?调试的时候没有传递值到数组
if ( *p == '\0')
//检测最后一个'\0'用于终止循环
if (t == strlen(tmp))
a[i][0] = '\0'; //添加结束符
printf("%d",i);
for(;i&=0;i--)
puts(a[i]);
如果您想提高自己的技术水平,欢迎加入本站官方1号QQ群:&&,&&2号QQ群:,在群里结识技术精英和交流技术^_^
本站联系邮箱:

我要回帖

更多关于 listview控件 的文章

 

随机推荐