c++如何读入这样的数据?在线等

xiaochuaner 2005-11-06 06:52:21
46 0.0 0.0
Alpha Beta Gamma Cx Cy Cz Cmx Cmy Cmz
.0000 .0000 .0000 .0471 -.0548 -.0190 -.0010 .0000 -.0056
4.2190 .0000 .0000 .0420 .2734 -.0191 .0000 -.0009 -.0056
8.4380 .0000 .0000 .0347 .4926 -.0255 -.0018 -.0019 .0000

第2行的数据不读,
怎么写程序?
谢谢
...全文
174 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wylove 2005-11-07
  • 打赏
  • 举报
回复
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <iterator>
#include <algorithm>


using namespace std;

...
ifstream in_file( "d:\\a.txt" );
if ( !in_file)
{
cerr << "File error!" << endl;
return;
}

istream_iterator< string > is( in_file );
istream_iterator< string > eof;
vector< string > text;

copy( is, eof, back_inserter( text ) );
...
将内容通过输入输出迭代器全部取到vector中,然后再进行处理。
wzjall 2005-11-06
  • 打赏
  • 举报
回复
#pragma warning(disable:4786)
#include<iostream>
#include<fstream>
#include<string>
using namespace std;

void main()
{
string s;
string fileName;
cin>>fileName;
ifstream in(fileName.c_str());
int row=1;
while(getline(in,s))
{
if(row++==2)
continue;
else
{
//do what you what to do!
}
}
wzjall 2005-11-06
  • 打赏
  • 举报
回复
同意楼上的
tdrhsb 2005-11-06
  • 打赏
  • 举报
回复
可以通过判断回车符号 啊,把第一个回车和第二个回车之间的内容不读

65,187

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧