@ForEveR
В астрале
7991 / 4750 / 321
Регистрация: 24.06.2010
Сообщений: 10,547
|
09.03.2011, 13:04
|
|
Можно как-нибудь так например
C++ | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
| #include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <string>
struct reader
{
public:
reader(std::ifstream& ifs2):ifs(ifs2)
{
}
~reader()
{
ifs.close();
}
std::string operator () ()
{
std::string res;
if(!ifs.eof())
std::getline(ifs, res);
return res;
}
private:
std::ifstream& ifs;
};
int count_Strings(std::ifstream& ifs)
{
std::string str;
int count=0;
while(std::getline(ifs, str))
++count;
return count;
}
int main()
{
std::vector<std::string> vec;
std::ifstream ifs("input.txt");
if(!ifs)
{
std::cerr<<"Error with opening file\n";
return 1;
}
int cnt=count_Strings(ifs);
ifs.close();
std::ifstream ifs2("input.txt");
if(!ifs2)
{
std::cerr<<"Error with opening file\n";
return 1;
}
reader file(ifs2);
vec.resize(cnt);
std::generate_n(vec.begin(), cnt, file);
std::copy(vec.begin(), vec.end(), std::ostream_iterator<std::string>(std::cout, "\n"));
return 0;
} |
|
1
|