| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1765 人关注过本帖
标题:C++从txt中读取数据
取消只看楼主 加入收藏
jszjvictor
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2013-1-3
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:4 
C++从txt中读取数据
请教大家怎么从一个有描述的txt中读取数字,而忽略描述,比如:
//total length l: 1                                             
//total time tpmax:1
//time step interval dt: 1.0e-6
//define cell number n: 100
//choice of boundary conditions(1: DIR; 2: ZGD; 3: PER) B: 1
//choice of convection types(1: UDS; 2: CDS; 3: TVD) C: 1
//switch on diffusion?(diffusion: 1; no diffusion: 0) dif: 0
//switch on convection?(convection: 1; no convection: 0) con: 1
就是说C++需要读取的只有每行末尾:后的的那个数字
搜索更多相关主题的帖子: number choice 
2013-01-28 06:02
jszjvictor
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2013-1-3
收藏
得分:0 
回复 3楼 rjsp
谢谢~文件就是上面这样的,读取冒号之后的数字,然后赋给c++里面相应的参数
没有说明只有数字的时候,我是这么写的:
程序代码:
double l, tpmax, dt;                                                        //define variables
    int n, w, B, C, dif, con;                                                   //define variables
    ifstream inputdata("parameter.txt");                                        //open the parameter file
    inputdata>>l>>tpmax>>dt>>n>>w>>B>>C>>dif>>con;                              //read the parameters to the variables
    inputdata.close();                                                          //close the parameter file

想请教要想前面加上说明,怎么只读冒号后面的数字
2013-01-29 20:29
jszjvictor
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2013-1-3
收藏
得分:0 
回复 6楼 TonyDeng
文件就是上面这样的,读取冒号之后的数字,然后赋给c++里面相应的参数
没有说明只有数字的时候,我是这么写的:
程序代码:
double l, tpmax, dt;                                                        //define variables
    int n, w, B, C, dif, con;                                                   //define variables
    ifstream inputdata("parameter.txt");                                        //open the parameter file
    inputdata>>l>>tpmax>>dt>>n>>w>>B>>C>>dif>>con;                              //read the parameters to the variables
    inputdata.close();                                                          //close the parameter file


想请教要想前面加上说明,怎么只读冒号后面的数字
2013-01-29 20:30
jszjvictor
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2013-1-3
收藏
得分:0 
回复 14楼 SwanK
谢谢,不过这不是我要的那种
2013-01-31 02:13
jszjvictor
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2013-1-3
收藏
得分:0 
回复 12楼 TonyDeng
谢谢!
2013-01-31 02:15
快速回复:C++从txt中读取数据
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012973 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved