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
相关阅读
有人知道 Addon Technologies 这个ICC吗? (转载)古德霸别骂架了 给新人指点指点学啥技术吧请问有没有大牛知道怎么绕过对虚拟打印机的限制?明天大家都去C* summit么?For single node persistence/storage急招湾区Android高手加盟startup做web application backend 有前途还是infra有前途对分布式软件的Jepsen测试请推荐嵌入式的显示架构使用注解方式的 ORM 框架的性能不行吧大家不觉得这篇文章很有道理么?未来语言的趋势?atom很好用说句实在话,你们有用Java8 玩FP感到爽的吗?问个弱智问题,js除了前端和node.js这种framework,还能用在哪里?请教一个设计js framework问题今天出了个 bug,给大家提个醒今天看一段spark程序快吐了goodbug,什么时候在java里用Groovy?go很牛啊。这个10ms 非常快了。知乎日报