Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 364169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:24:45+00:00 2026-05-12T13:24:45+00:00

My counter is jumping from 1 to 4 when I enter my loop. Any

  • 0

My “counter” is jumping from 1 to 4 when I enter my loop. Any ideas? Code and output below:

    static bool harvestLog()
{
    ifstream myFile("LOGS/ex090716.log");
    if (myFile.fail()) {cout << "Error opening file";return 1;}
    else
    {
        cout << "File opened... \n";
        string line;
        string field;
        int cs_uri_stemLocation = 0;
        int csReferrerLocation = 0;
        int count = 1;
        cout << "-" << count << "-";
        while( getline(myFile, line) ) {
            if ( strstr(line.c_str(), "cs-uri-stem") &&
                (strstr(line.c_str(), "cs(Referer)") || strstr(line.c_str(), "cs(Referrer)")) )
            {
                cout << "-" << count << "-";
                cout << "Found log format: \n";
                istringstream foundField(line);
                while (!foundField.eof())
                {
                    cout << "-" << count << "-";
                    foundField >> field;
                    if (field == "cs-uri-stem") {cs_uri_stemLocation = count;}
                    if (field == "cs(Referer)" || field == "cs(Referrer)") {csReferrerLocation = count;}
                    cout << "cs-uri-stem: " << cs_uri_stemLocation << ". ";
                    cout << "cs(Referer): " << csReferrerLocation << ". ";
                    cout << "COUNT: " << count << endl;
                    count++;
                }
                cout << "Found field cs-uri-stem at position " << cs_uri_stemLocation << "." << endl;
                cout << "Found field cs(Referer) at position " << csReferrerLocation << "." << endl;
                count = 1;
            }
            else
            {
                count = 1;
                istringstream foundField(line);
                while (!foundField.eof())
                {
                    foundField >> field;
                    //if (count == cs_uri_stemLocation) cout << field << endl;
                    count++;
                }

                //cmatch results;
                //regex rx("(?:p|q)(?:=)([^ %]*)");
                //regex_search(line.c_str(), results, rx);
                //string referringWords = results[1];

                //cout << referringWords;
            }
        }
    myFile.close();
    return 0;
    }
}

-1–4-Found log format:
-4-cs-uri-stem: 0. cs(Referer): 0. COUNT: 4
-5-cs-uri-stem: 0. cs(Referer): 0. COUNT: 5
-6-cs-uri-stem: 0. cs(Referer): 0. COUNT: 6
-7-cs-uri-stem: 0. cs(Referer): 0. COUNT: 7
-8-cs-uri-stem: 0. cs(Referer): 0. COUNT: 8
-9-cs-uri-stem: 0. cs(Referer): 0. COUNT: 9
-10-cs-uri-stem: 10. cs(Referer): 0. COUNT: 10
-11-cs-uri-stem: 10. cs(Referer): 0. COUNT: 11
-12-cs-uri-stem: 10. cs(Referer): 0. COUNT: 12
-13-cs-uri-stem: 10. cs(Referer): 0. COUNT: 13
-14-cs-uri-stem: 10. cs(Referer): 0. COUNT: 14
-15-cs-uri-stem: 10. cs(Referer): 0. COUNT: 15
-16-cs-uri-stem: 10. cs(Referer): 16. COUNT: 16
-17-cs-uri-stem: 10. cs(Referer): 16. COUNT: 17
-18-cs-uri-stem: 10. cs(Referer): 16. COUNT: 18
-19-cs-uri-stem: 10. cs(Referer): 16. COUNT: 19
-20-cs-uri-stem: 10. cs(Referer): 16. COUNT: 20
Found field cs-uri-stem at position 10.
Found field cs(Referer) at position 16.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T13:24:45+00:00Added an answer on May 12, 2026 at 1:24 pm

    I would bet that it’s going throught the

                            while (!foundField.eof())
                            {
                                    foundField >> field;
                                    //if (count == cs_uri_stemLocation) cout << field << endl;
                                    count++;
                            }
    

    and you never reset it after this branch

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Code: static int counter = 0; int add(int x) { counter++; return ++x; }
Is there any default Counter Variable in For loop?
UPDATE counter_reports SET `counter`=`counter`+1,`date`=? WHERE report_id IN( (SELECT report_id FROM counter_reports WHERE report_name=emails_sent AND
I have a tap counter and this is the Who Wins code. The app
Counter objects are subclasses of dict so they have the method setdefault. >>> from
I want a counter that increases on button click. I tried the following code,
I have two modules counter: Output is a vector called error_count. lcd: Module to
Query: select max(b.counter) as counter, b.m_group, b.m_code, a.s_id, s.id_sk from tbl_various a, tbl_map b,
How to get a counter inside xsl:for-each loop that would reflect the number of
Is there any performance counter? Or i really get result like that: Jagged Arrays:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.