Search Results

Search found 3 results on 1 pages for 'shap'.

Page 1/1 | 1 

  • count specific things within a code in c++

    - by shap
    can anyone help me make this more generalised and more pro? #include <fstream> #include <iostream> #include <string> #include <vector> using namespace std; int main() { // open text file for input: string file_name; cout << "please enter file name: "; cin >> file_name; // associate the input file stream with a text file ifstream infile(file_name.c_str()); // error checking for a valid filename if ( !infile ) { cerr << "Unable to open file " << file_name << " -- quitting!\n"; return( -1 ); } else cout << "\n"; // some data structures to perform the function vector<string> lines_of_text; string textline; // read in text file, line by while (getline( infile, textline, '\n' )) { // add the new element to the vector lines_of_text.push_back( textline ); // print the 'back' vector element - see the STL documentation cout << lines_of_text.back() << "\n"; } cout<<"OUTPUT BEGINS HERE: "<<endl<<endl; cout<<"the total capacity of vector: lines_of_text is: "<<lines_of_text.capacity()<<endl; int PLOC = (lines_of_text.size()+1); int numbComments =0; int numbClasses =0; cout<<"\nThe total number of physical lines of code is: "<<PLOC<<endl; for (int i=0; i<(PLOC-1); i++) //reads through each part of the vector string line-by-line and triggers if the //it registers the "//" which will output a number lower than 100 (since no line is 100 char long and if the function does not //register that character within the string, it outputs a public status constant that is found in the class string and has a huge value //alot more than 100. { string temp(lines_of_text [i]); if (temp.find("//")<100) numbComments +=1; } cout<<"The total number of comment lines is: "<<numbComments<<endl; for (int j=0; j<(PLOC-1); j++) { string temp(lines_of_text [j]); if (temp.find("};")<100) numbClasses +=1; } cout<<"The total number of classes is: "<<numbClasses<<endl;

    Read the article

1