Ну если по простому:
| Код | #include <iostream> #include <fstream>
int TextSize(std::ifstream& file) { int count = 0; while (true) { std::string buf; std::getline(file, buf, '\n'); if ( file.fail() ) break; ++count; } return count; }
int main(int argc, char* argv[]) { std::ifstream file("d:\\str.txt"); std::cout << TextSize(file); std::cin.sync(); std::cin.get(); return 0; }
|
Добавлено через 1 минуту и 43 секунды Упс, не так реализовал. Вот:
| Код | #include <iostream> #include <fstream>
int TextSize(const std::string& Name) { int count = 0; std::ifstream file( Name.c_str() ); if ( !file.is_open() ) return -1; while (true) { std::string buf; std::getline(file, buf, '\n'); if ( file.fail() ) break; ++count; } return count; }
int main(int argc, char* argv[]) { std::cout << TextSize("d:\\str.txt"); std::cin.sync(); std::cin.get(); return 0; }
|
|