what is the easist way find out the number of lines in a txt file?
there seems to be a function to ignore rest of the line...will that help?
conan19870619 0 Newbie Poster
Recommended Answers
Jump to Post— Duoas 1,025Use the STL
#include <algorithm> #include <fstream> #include <iostream> #include <iterator> using namespace std; int main( int argc, char** argv ) { if (argc < 2) { cout << "usage:\n countlines FILENAME\n"; return 0; } ifstream file( argv[ 1 ] ); if (!file) { cerr << "Could …
Jump to Post— vijayan121 1,152
> cat my_file.txt | grep ^ | wc -l
Jump to Post— Ancient Dragon 5,243
> cat my_file.txt | grep ^ | wc -lThat doesn't satisfy the c++ requirement. If the op is writing shell scripts that would be perfect, but this isn't shell script programming.
Jump to Post— Radical Edward 301+1 // the last line is not terminated by NLBut if the last line is terminated by NL, the count will be wrong. Sometimes it's better to be boring and conventional instead of clever and daring. ;)
#include <iostream> #include <sstream> #include <string> …
All 13 Replies
Duoas 1,025 Postaholic Featured Poster
Ancient Dragon commented: I like it -- although slightly obscure. +35
vijayan121 1,152 Posting Virtuoso
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Radical Edward 301 Posting Pro
Duoas 1,025 Postaholic Featured Poster
mitrmkar 1,056 Posting Virtuoso
Member #46692
Member #46692
Radical Edward 301 Posting Pro
Duoas 1,025 Postaholic Featured Poster
Radical Edward 301 Posting Pro
Duoas 1,025 Postaholic Featured Poster
Radical Edward 301 Posting Pro
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.