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

编程入门 行业动态 更新时间:2024-10-24 12:21:56
本文介绍了如何打开文件,跳过前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>在留言中写道 news:bm *********** @ news.hgc.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> wrote in message news:bm***********@news.hgc.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>在留言中写道 news:bm *********** @ news.hgc.hk ... Oops in my previous post that should be ifstream of course. Regards, Ron AF Greve. "FrancisC" <fr**********@hong-kong.crosswinds> wrote in message news:bm***********@news.hgc.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>写道: "FrancisC" <fr**********@hong-kong.crosswinds> 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个字符?

本文发布于:2023-11-10 21:55:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1576568.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:跳过   字符   文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!