Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > C/C++: Для новичков > Работа с файлами. Нужна помощь


Автор: goody 4.6.2009, 16:30
Помогите написать. Есть файл input.txt со словами. Нужно слова n-ой длины записать в файл output.txt.. Можно на C или C++ 
Прост я не понимаю как проверять EOF  

Автор: Курсант 4.6.2009, 16:54
smile Сбылась мечта идиота smile 

Код

#include <iostream>
#include <fstream>
using namespace std;

int main()
{
    char chWord[80];
    char chOutFileName[80];
    cout << "Enter input file name: ";
    cin >> chWord;
    int len;
    cout << "Enter length of words: ";
    cin >> len;
    cout << "Enter the input file name: ";
    cin >> chOutFileName;
    ifstream fin (chWord);
    ofstream fout (chOutFileName);
    while (!fin.eof())
    {
        fin >> chWord;
        if (strlen(chWord) == len)
            fout << chWord << endl;
    }
    fin.close();
    fout.close();
    return 0;
}

Автор: Static 4.6.2009, 16:59
 smile 
Мечта - успеть первым написать кодик?  smile 

Автор: azesmcar 4.6.2009, 16:59
Код

#include <fstream>
#include <functional>
#include <iostream>
#include <string>
#include <algorithm>
#include <iterator>

struct check_length : std::binary_function<std::string, int, bool>
{
    bool operator ()(const std::string& r, int n) const {
        return (r.size() != n);
    }
};

int main()
{
    const int n = 4;

    std::ifstream inp("input.txt");
    std::ofstream out("output.txt");

    std::remove_copy_if(
        std::istream_iterator<std::string>(inp),
        std::istream_iterator<std::string>(),
        std::ostream_iterator<std::string>(out, " "),
        std::bind2nd(check_length(), n)
    );

    inp.close();
    out.close();
}


Автор: goody 4.6.2009, 22:09
Почему с русскими словами не работает? 

Автор: Курсант 4.6.2009, 23:24
У меня все работало...

Автор: goody 5.6.2009, 10:21
spasibo

Автор: Курсант 15.6.2009, 23:36
Цитата(goody @  4.6.2009,  22:09 Найти цитируемый пост)
Почему с русскими словами не работает?  


Цитата(goody @  5.6.2009,  10:21 Найти цитируемый пост)
spasibo


 smile Слушай, расскажи, чего ты с этой программой делал???

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)