从txt文件中逐行导入数字并按数字顺序显示到控制台屏幕? [英] Import numbers from a txt file, line by line and display them in numeric order to the console screen?

查看:138
本文介绍了从txt文件中逐行导入数字并按数字顺序显示到控制台屏幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试访问一个名称为数字的txt文件,并根据数字顺序组织这些行。然后将项目输出到控制台屏幕。



我尝试过:



I am trying to access a txt file that has a name then a number and organize the lines according to numeric order. Then output the project to the console screen.

What I have tried:

#include <iostream>
#include <iterator>
#include <vector>
#include <algorithm>

int main() {
  std::vector<std::string> vals;

  std::copy(
    std::istream_iterator<std::string>(std::cin),
    std::istream_iterator<std::string>(),
    std::back_inserter(vals)
  );

  // Print them out, appending a newline to each word

  std::copy(
    vals.begin(),
    vals.end(),
    std::ostream_iterator<std::string>(std::cout, "\n")
  );
}

推荐答案

您必须学习C ++ 并阅读第18章的文件I / O.
You must Learn C++ and read the chapter 18 for file I/O.


这篇关于从txt文件中逐行导入数字并按数字顺序显示到控制台屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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