|
|
|
? найти слова определенной длины в файле
|
|||
|---|---|---|---|
|
#18+
#include<iostream.h> #include<fstream.h> void main() { char slovo; ifstream original("original.txt")/*файл для чтения*/; ofstream vivod ("vivod.txt")/*файл для записи*/; original.unsetf (ios::skipws); while(original>>slovo)/*чтение чисел из файла*/ if (slovo=='a') vivod<<slovo; original.close();/*файл закрыт*/ vivod.close();/*файл закрыт*/ } ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 23.05.2005, 08:28 |
|
||
|
? найти слова определенной длины в файле
|
|||
|---|---|---|---|
|
#18+
// найти все слова определенной длины #include <iostream> #include <string> #include <iterator> #include <algorithm> #include <fstream> template<class InIt, class OutIt, class Pred> OutIt copy_if(InIt first, InIt last, OutIt x, Pred p) { for( ; first != last; ++first) if( p(*first) ) { *x = *first; ++x; } return x; } struct len_equal_to { size_t l; explicit len_equal_to(size_t l) : l(l) {} bool operator()(std::string const &s) const { return s.length() == l; } }; int main() { ifstream original("original.txt")/*файл для чтения*/; ofstream vivod ("vivod.txt")/*файл для записи*/; copy_if( std::istream_iterator<std::string>(original), (std::istream_iterator<std::string>()), std::ostream_iterator<std::string>(vivod, "\n"), len_equal_to(5) ); return 0; } ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 23.05.2005, 13:02 |
|
||
|
|

start [/forum/topic.php?fid=57&msg=33079248&tid=2033265]: |
0ms |
get settings: |
10ms |
get forum list: |
13ms |
check forum access: |
3ms |
check topic access: |
3ms |
track hit: |
36ms |
get topic data: |
10ms |
get forum data: |
2ms |
get page messages: |
46ms |
get tp. blocked users: |
1ms |
| others: | 242ms |
| total: | 366ms |

| 0 / 0 |
