读取文件& C ++的子字符串 [英] read file & substring with C++

查看:65
本文介绍了读取文件& C ++的子字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个txt文件,看起来像这样:

2
123111132
23 34 444
3
233 33

从文件读取并获取每个值的最简单方法是什么?
编译时间很重要!
-这是一场编程比赛-
请不要用Google搜索链接回答!
谢谢大家

I have a txt file looks like this:

2
123 111 132
23 34 444
3
233 33

What is the easiest way to read from a file & to get each of the values?
Compailing time is important!
-This is for a programming contest-
Please don''t answer with a google search link!
Thanks every body

推荐答案

您为什么认为我们会帮助您作弊赢得比赛?
听起来对所有大概自己做过的其他人来说公平吗?
Why do you think we would help you cheat to win a contest?
Does that sound fair to all the others who have presumably done it themselves?


可能最快的方法是使用低级IO(打开/读取或fopen/读取).但是,使用如此小的程序,无论您选择哪种版本,编译时间都不太可能大不相同.您可以很容易地找到上述功能的引用.我会发布一个Google链接,但您告诉我们不要.
Probably the fastest way to do it would be to use low level IO (open/read or fopen/fread). However, with a program this small it''s unlikely that compile time will be significantly different whichever version you choose. You can find the references to the above functions quite easily; I would post a Google link but you told us not to.


您需要在此处进行一些试验/错误.创建一些不同的代码段.然后分别使用不同的编译器进行尝试.然后选择可以为您提供最佳编译时间的编译器/代码组合.机器本身可能无关紧要,因为您的代码足够小,以至于多个CPU不会有太大帮助.但是从SSD甚至RAM驱动器上运行编译器和源文件将进一步提高速度.

不过,这很奇怪,因为编译器的速度与您作为编码器的能力无关.
You''d need to do some trial/error here. Create a few different code snippets. Then try them each with different compilers. Then pick the compiler/code combination that gives you the best compile-time. The machine itself probably won''t matter since your code will be small enough that multiple CPUs won''t help much. But running the compiler and the source file off an SSD or even a RAM-drive will further boost speeds.

Weird contest though, since the compiler''s speed has nothing to do with your ability as a coder.


这篇关于读取文件& C ++的子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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