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 PostUse 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
> cat my_file.txt | grep ^ | wc -l
That 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 PostDefine line:
Is the below:
fdsa \n \n fdsf
4 lines or just two?
Jump to PostHow about the below? But then you might also want to consider if it should also ignore a line full of spaces. Again it all depends on your definition.
#include <iostream> #include <fstream> #include <string> using namespace std; class Foo { public: void bar() { ifstream file …
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

iamthwee

iamthwee
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.