Quote:Original post by SlippyPulse
Hey, i used dev cpp and i didn't have a compiler
Dev Cpp is a compiler too. Click on the "execute" menu and then click "compile and run."
May the force be with you. All of you.
Quote:Original post by SlippyPulse
Hey, i used dev cpp and i didn't have a compiler
Quote:Original post by MSalley
Dev Cpp is a compiler too. Click on the "execute" menu and then click "compile and run."
Quote:Original post by Raduprv
Add this at the beginning of your program:
printf("Here is what argument 3 is: %s",argv[3]);
Then see what it says.
#include <fstream>#define MAX_LENGTH 255//MAX_LENGTH is the length of the longest line in your file or longer.ifstream file;file.open("whatever.wht");int ctr = 0;char *t[MAX_LENGTH];while(!file.eof()) { file.getline(t, MAX_LENGTH); ctr++; }
ifstream file;
// In C++ we should use const identifiers for constants rather than #defines// where possible: thus, "const int MAX_LENGTH = 255;"// However, we won't need this value anyway :)#include <fstream>// Note that new C++ headers place all this stuff in the std namespace.// fstream.h does not, but it's a backwards-compatibility hack for old code and// should not be used these days (marked deprecated).#include <limits> // for version A#include <string> // for version B// The ifstream offers a constructor accepting the same parameters as a .open()// call, so in the normal case we may as well use it directlystd::ifstream file("whatever.wht");int counter = 0;std::string buffer; // for version B// VERSION Awhile(file.ignore(std::numeric_limits<streamsize>::max(), '\n')) { counter++; }// I think I "spelled" all of that correctly. We "ignore" (skip past) lines// until the return value (which is '*this' - i.e. 'file') evaluates false// (which happens at end of file, or if there is some other serious problem).// VERSION Bwhile(std::getline(file, buffer)) { counter++; }// Similarly, we read lines into a string (that will resize itself appropriately// regardless of the data) until EOF.