1

Is there a quick way, in Visual Studio, to know how many lines of code exist in a project?

Shog9
  • 156,901
  • 35
  • 231
  • 235

6 Answers6

5

In Visual Studio 2008, right click a project and select "Calculate Code Metrics". It includes a few other metrics like cyclomatic complexity. However, it only counts real lines of code, not empty lines or lines with }'s for example.

Paul Stovell
  • 32,377
  • 16
  • 80
  • 108
  • What version(s) of VS2008 is this in? I'm running Professional, and don't see it... – Shog9 Feb 23 '09 at 19:50
  • It is team edition only - on the developer menu. Not that we have it, because like most people we don't use team. – Bob Moore Feb 23 '09 at 20:17
2

Install cygwin, start a bash shell, cd to the top directory and issue something like:

find . -name "*.cpp" -exec cat {} \; | wc -l

Paul.

Paul W Homer
  • 2,728
  • 1
  • 19
  • 25
  • This ignores .c/.h files, forks a new process for every source file, doesn't give a final total, and counts meaningless lines (blank lines, comments, lines containing only braces, etc.) – Adam Rosenfield Feb 23 '09 at 20:15
  • I generally get the counts for the header files independently; don't care about CPU usage and believe that there are no such things as meaningless lines. – Paul W Homer Feb 23 '09 at 21:05
  • You can also do 'find . -name "*cpp" | xargs cat | wc -l', or in zsh (and possibly bash 4) 'wc -l **/*cpp | tail -n1'. How do you do it in windows without visual studio? – Jonas Kölker Mar 19 '09 at 21:57
  • Install a Unix shell like Cygwin. Or if you have a real sense of fun, install a VM emulator like VirtualBox, and a Linux distro like Debian, share the Windows filesystem into Samba and then hit the sources directly with bash. – Paul W Homer Mar 21 '09 at 15:42
1

You could always use the line counter add-in from the sample code.

Yes - that Jake.
  • 16,725
  • 14
  • 70
  • 96
1

I've used SourceMonitor. Works well enough.

See also the answers on: Simple script to count NLOC?

Community
  • 1
  • 1
Shog9
  • 156,901
  • 35
  • 231
  • 235
1

For a more general solution which will give you line counts and many more useful metrics, I can strongly recommend Source Monitor which is free and can be integrated with VS.

0

I regularly use http://cloc.sourceforge.net/ to obtain code metrics on several languages including C++.

user8128167
  • 6,929
  • 6
  • 66
  • 79