Help displaying number before .txt file

I am making a program that shows the contents of the .txt file when asked for. My program does everything correctly, but I need to have the line number followed by a colon before each line, I am unable to get that to work correctly in the program. Any help would be great.

For example. If the first line is "The dog is big", i need the output to display '1:The dog is big' and the 2nd line needs '2:' before the words and so forth
Hopefully this is not too much (or too little), but this worked okay for me

1
2
3
4
5
6
7
8
9
10
11
12
13
. . .

    ifstream fileIn;
    fileIn.open("data/s.txt");
    int nLine(1);
    string sLine("");
    do {
        getline(fileIn, sLine, '\n');
        if(sLine.length() > 0) {   
            cout << nLine++ << ": " << sLine << endl; } }
    while(!fileIn.eof());

. . .
Topic archived. No new replies allowed.