s*r
2 楼
Here is my solution. It is not necessarily the simplest one.
I use f.seek(-60, ios::end) here, assuming:
1. the data file is in Text Format;
2. the last 2nd number is always within the last 60 bytes of the data file.
The last 2nd element in the vector v is what you want, then.
#include
#include
#include
#include
using namespace std;
int main(void){
ifstream f("1.data");
f.seekg(-60, ios::end);
vector
【在 x*****u 的大作中提到】
: 我想读某数据文件中最后一行第二个数,C(++)有没有简单易行的法子?
: 谢谢!
x*u
3 楼
感谢! 但感觉这个-60不好把握,多了少了都成问题。
用getline应该更稳妥一点。
1 // istringstream::str
2 #include
3 #include
4 #include
5 #include
6 using namespace std;
7
8 int main () {
9
10 double val;
11
12 string file_name("Tnve.dat");
13 ifstream infile(file_name.c_str(),ios::in);
14 istringstream iss;
15 string strvalues,sv;
16
【在 s******r 的大作中提到】
:
: Here is my solution. It is not necessarily the simplest one.
: I use f.seek(-60, ios::end) here, assuming:
: 1. the data file is in Text Format;
: 2. the last 2nd number is always within the last 60 bytes of the data file.
: The last 2nd element in the vector v is what you want, then.
: #include
: #include
: #include
: #include
用getline应该更稳妥一点。
1 // istringstream::str
2 #include
3 #include
4 #include
5 #include
6 using namespace std;
7
8 int main () {
9
10 double val;
11
12 string file_name("Tnve.dat");
13 ifstream infile(file_name.c_str(),ios::in);
14 istringstream iss;
15 string strvalues,sv;
16
【在 s******r 的大作中提到】
:
: Here is my solution. It is not necessarily the simplest one.
: I use f.seek(-60, ios::end) here, assuming:
: 1. the data file is in Text Format;
: 2. the last 2nd number is always within the last 60 bytes of the data file.
: The last 2nd element in the vector v is what you want, then.
: #include
: #include
: #include
: #include
相关阅读
本科非计算机专业平均分78能上ITU的CS master吗Go lang有多少公司 组 在用到底新的<Web技术日报 >请大家推荐个免费FTP server (linux)作为程序员,oracle database需要掌握什么方面?不懂fp搞不了scala[KJPT]谷歌在补丁发布日前披露Windows漏洞 微软怒了 (转载)PhD在读,被三哥拉着创业 (转载)jsoup真是好东东用 golang build 一个 HA 的 distributed system一般怎么搞?ibm要雷四分之一人力?PHP在Web开发中还有前途吗?Java 8的streaming大牛讲讲mongoDB这种开源的怎么赚钱?重回首,看当年的帖子一项技术的生命力有多久?Go再不靠谱也比scala强感觉控制反转是印度人发明出来忽悠人的Google Glass sales halted but firm says kit is not dead有人用docker deploy node app吗?