简单的C ++输入文件-.- [英] Simple C++ Input File -.-

查看:52
本文介绍了简单的C ++输入文件-.-的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,实现我想要的东西真的很容易.
但是..我需要最好的方法..
我想加载一个.txt文件.

.txt:

So, Its really easy to make what I want.
But .. I need the best way ..
I want to load a .txt file.

.txt:

Text 0 50 600
TextIt 3 60 800



只需将文本"作为strig(char)加载
和数字作为(int)

并对接下来的行进行相同操作..



Just load ''Text'' as a strig (char)
and the numbers as a (int)

And do the same for the next lines ..

推荐答案

示例C++代码
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main()
{
  string str;
  int x,y,z;
  ifstream ifs("input.txt");

  while (ifs.good())
  {
    ifs >> str >> x >> y >> z;
    cout << str << " {" << x << ", " << y << ", " << z << "}" << endl; 
  }
}


使用fopen(),fgets(),fclose()逐行读取文本文件,并使用sscanf()或regex [
Use fopen(), fgets(), fclose() to read the text file line-by-line, and use sscanf() or regex[^] to process the individual lines.


这篇关于简单的C ++输入文件-.-的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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