Getting the width of a line from a file

Hi everbody
i wantto get the width of a line from a file.somehow i got this code
#include <vector>
#include <string>
#include <fstream>
#include <iostream>
#include <cmath>
using namespace std;

int main(int argc, char* argv[]) {
ifstream in(argv[1]);
string line;
vector<string> lines;
while(getline(in, line)) // Read in entire file
lines.push_back(line);
if(lines.size() == 0) return 0;
int num = 0;
// Number of lines in file determines width:
const int width = int(log10(lines.size())) + 1;
for(int i = 0; i < lines.size(); i++) {
cout.setf(ios::right, ios::adjustfield);
cout.width(width);
cout << ++num << ") " << lines[i] << endl;
}
}

I cant understand the logic behing the BOLD and UNDERLINED statement ..Plz if anyone can let me know how its working
help would be appreciated.
It's not getting the width of any line. It's taking the size of 'lines', which is a vector, and figuring out how many digits the decimal representation of that value uses.
Another way a little easier to understand (and probably even faster) is to repeatedly divide by 10.
Topic archived. No new replies allowed.