Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all articles
Browse latest Browse all 3021

Program shoudn't count comments and blank lines

$
0
0
OK, I'm making some progress. My program does compile and output the number of line per code, but it shouldn't count comments and blank lines. I tried using (s.substr(0,2) == "//") as suggested but it didn't work. I definitely appreciate any recommendations and suggestions. Thanks guys.
This is my improved code:
Code:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

const int A = 3;

int main()
{
string s;
ifstream myfile ("example.cpp");
int count = 0;
//int A = 3;
getline(myfile, s);

if (myfile.is_open())
{
while ( getline (myfile, s) ){
count++;
if (s[0] == '/' || s[0] == ' ' || s[0] == '#'){
count--;
}

}

}
cout << "This is your LOC: " << count << endl;
return 0;
}


Viewing all articles
Browse latest Browse all 3021

Trending Articles