从文件中读取行 [英] reading lines from file
问题描述
问题很简单,我有一个名为primes.txt的文件。并且
有趣,它包含很多素数(每行一个)
除此之外我还有一个空矢量:
vector< __ int64> P(0);
如何填写文件内容?
P.push_back(第1行);
P.push_back(第2行);
ect。
我用getline()尝试了不同的东西,但它不会工作。
希望有人能尽快帮助。
问候
Zacariaz
The question is pretty simple, i have a file called "primes.txt" and
funny enough it contains alot of primes (one per line)
Besides that i have an empty vector:
vector<__int64> P(0);
How do i fill that with the contents of the file?
P.push_back(line 1);
P.push_back(line 2);
ect.
I have tryed different stuff with getline() but it just wont work.
Hope someone can help ASAP.
Regards
Zacariaz
推荐答案
fe ********** @ hotmail.com 写道:
问题很简单,我有一个名为primes.txt的文件。并且
有趣的是它包含很多素数(每行一个)
除此之外我还有一个空矢量:
vector< __ int64> P(0);
如何填写文件内容?
P.push_back(第1行);
P.push_back(第2行); <等等。
我用getline()尝试了不同的东西,但它不会工作。
希望有人能尽快帮忙。
The question is pretty simple, i have a file called "primes.txt" and
funny enough it contains alot of primes (one per line)
Besides that i have an empty vector:
vector<__int64> P(0);
How do i fill that with the contents of the file?
P.push_back(line 1);
P.push_back(line 2);
ect.
I have tryed different stuff with getline() but it just wont work.
Hope someone can help ASAP.
该文件提供了一系列值,您需要将
序列复制到一个向量中:
ifstream输入(" primes。 tx");
copy(istream_iterator< __ int64>(输入),istream_iterator< __ int64>(),
back_inserter(p));
这是一个基本习语。学习它。
-
Pete Becker
Dinkumware,Ltd。( http://www.dinkumware.com )
Im试着学习,这就是为什么我要问...
无论如何谢谢答案...
Im trying to learn, thats why im asking...
anyway thank for the answer...
fe ********** @ hotmail.com 写道:
Im试图学习,这就是为什么我要问...
Im trying to learn, thats why im asking...
对不起,这并不意味着听起来像是放下。
>
-
Pete Becker
Dinkumware,Ltd。( http://www.dinkumware.com )
这篇关于从文件中读取行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!