如何打开文件,跳过前2行并获得第50个字符? [英] How can I open a file, skip first 2 lines and get the 50th character?

查看:83
本文介绍了如何打开文件,跳过前2行并获得第50个字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何打开文件,跳过前2行并获得第50个字符?


EXP 0 R:\000\un\111\ e00 \ e00noLog \ 1006 \bdry_arc.e00

ARC 2

1 1 0 0 0 0 7


即我想要得到7在第三行,我该怎么做?


thx !!

How can I open a file, skip first 2 lines and get the 50th character?

EXP 0 R:\000\un\111\e00\e00noLog\1006\bdry_arc.e00
ARC 2
1 1 0 0 0 0 7

i.e., I want to get the "7" in the third line, how can I do that?

thx!!

推荐答案

你好,


#include< fstream>

#include< string>

使用命名空间std;


int main()

{

int RetVal = 0;

ofstream输入(" Filename");

if(!Input.is_open())

{

//可以使用异常,但因为它太小了......

RetVal = 1;

}

其他

{

string Line;

getline(输入,线路);

getline(输入,线路);

getline(输入,线路);

cout<<输入[49]<<结束;

}


返回RetVal;

}


TODO添加一些更多的错误检查。


问候,Ron AF Greve。

" FrancisC" < FR ********** @ hong-kong.crosswinds.net>在留言中写道

news:bm *********** @ news.hgc.com.hk ...
Hi,

#include <fstream>
#include <string>
using namespace std;

int main()
{
int RetVal = 0;
ofstream Input( "Filename" );
if( !Input.is_open() )
{
// Could use exceptions, but since it is so small...
RetVal = 1;
}
else
{
string Line;
getline( Input, Line );
getline( Input, Line );
getline( Input, Line );
cout << Input[ 49 ] << endl;
}

return RetVal;
}

TODO add some more error checking.

Regards, Ron AF Greve.
"FrancisC" <fr**********@hong-kong.crosswinds.net> wrote in message
news:bm***********@news.hgc.com.hk...
如何打开文件,跳过前2行并获得第50个字符?

EXP 0 R:\000\un \111 \ e00 \ e00noLog \ 1006 \bdry_arc.e00
ARC 2
1 1 0 0 0 0 7

即,我希望得到7。在第三行,我该怎么做?

thx !!
How can I open a file, skip first 2 lines and get the 50th character?

EXP 0 R:\000\un\111\e00\e00noLog\1006\bdry_arc.e00
ARC 2
1 1 0 0 0 0 7

i.e., I want to get the "7" in the third line, how can I do that?

thx!!



在我以前的帖子中哎呀那当然应该是ifstream。


问候,Ron AF Greve。

" FrancisC" < FR ********** @ hong-kong.crosswinds.net>在留言中写道

news:bm *********** @ news.hgc.com.hk ...
Oops in my previous post that should be ifstream of course.

Regards, Ron AF Greve.
"FrancisC" <fr**********@hong-kong.crosswinds.net> wrote in message
news:bm***********@news.hgc.com.hk...
如何打开文件,跳过前2行并获得第50个字符?

EXP 0 R:\000\un \111 \ e00 \ e00noLog \ 1006 \bdry_arc.e00
ARC 2
1 1 0 0 0 0 7

即,我希望得到7。在第三行,我该怎么做?

thx !!
How can I open a file, skip first 2 lines and get the 50th character?

EXP 0 R:\000\un\111\e00\e00noLog\1006\bdry_arc.e00
ARC 2
1 1 0 0 0 0 7

i.e., I want to get the "7" in the third line, how can I do that?

thx!!



" FrancisC" < FR ********** @ hong-kong.crosswinds.net>写道:
"FrancisC" <fr**********@hong-kong.crosswinds.net> writes:
如何打开文件,跳过前2行并获得第50个字符?

EXP 0 R:\\\\ \\ _111 \ e00 \ e00noLog \ 1006 \bdry_arc.e00
ARC 2
1 1 0 0 0 0 7

即,我想得到 7英寸;在第三行,我该怎么做?
How can I open a file, skip first 2 lines and get the 50th character?

EXP 0 R:\000\un\111\e00\e00noLog\1006\bdry_arc.e00
ARC 2
1 1 0 0 0 0 7

i.e., I want to get the "7" in the third line, how can I do that?




7是这一行的第70个字符,而不是第50个字符。


使用标准的unix工具做一些事情比重新发明更好:


head -3 bla |尾巴-1 | cut -b 50

亲切的问候

frank


-

弗兰克Schmitt

4SC AG电话:+49 89 700763-0

电子邮件:frankNO DOT SPAMschmitt AT 4sc DOT com



The 7 is the 70th character on this line, not the 50th.

Some things are better done with standard unix tools than reinvented:

head -3 bla | tail -1 | cut -b 50

kind regards
frank

--
Frank Schmitt
4SC AG phone: +49 89 700763-0
e-mail: frankNO DOT SPAMschmitt AT 4sc DOT com


这篇关于如何打开文件,跳过前2行并获得第50个字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆