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 8080843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:32:26+00:00 2026-06-05T16:32:26+00:00

I am new to C++ programming and am obviously missing something. In the following

  • 0

I am new to C++ programming and am obviously missing something. In the following code the compiler doesn’t seem to recognize this line: lengths[counter] = findDups(crtLine); I get an error: variable “lengths” set but not used. I cannot figure out why it is not recognizing this line, when the names[counter] = getNameOnly(crtLine) works perfectly and it is essentially the same format. Any insight into this issue is appreciated!

#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>

using namespace std;


string getNameOnly (string line) {
    return line.substr(0, line.find(' '));
}

int findDups (string line) {
    string lnCpy = line;
    sort(lnCpy.begin(), lnCpy.end());   
    int i = 0; 
    int dups = 0;
    int j = 1;
    int len = lnCpy.length();
    while (j < len) {
        if (lnCpy.at(i) == lnCpy.at(j))
                dups++;
        i++;
        j++;
    }

    if (dups != 0)
        return 0;
    else
            return lnCpy.length();
}

int main() {

string names[1219];
int lengths[1219];
string crtLine;
int counter = 0;

ifstream myfile ("dist.male.first");
if (myfile.is_open()) {
    while (!myfile.eof()) {
        getline(myfile,crtLine);
        lengths[counter] = findDups(crtLine);           
        names[counter] = getNameOnly(crtLine);                  
        counter++;
    }
    myfile.close();
}   
else cout << "Unable to open file";


return (0);

}

  • 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-06-05T16:32:27+00:00Added an answer on June 5, 2026 at 4:32 pm

    That’s a warning, not an error, and it tells you exactly what the problem is: you put things into the variable named lengths, but never check what’s in it, you might as well never store anything there in the first place.

    You don’t get a similar warning for names, because the assignment operator of std::string has side effects, and the compiler assumes you were interested in the side effect (rather than getting the value out later).

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

Sidebar

Related Questions

I'm new to event programming, and I'm obviously misunderstanding something that I'm trying to
New to programming. I wrote a Python code (with help from stackoverflow) to read
Totally new to programming so kindly excuse the silly question. I have this URL
Something I don't enjoy about programming is learning a new API. For example, right
I'm new to android programming and I'm having a little trouble with the following.
Being relatively new to functional programming, I expend lots of energy wondering is this
This is a continuation of the this question. I am new to network programming,
What features could be added to a new programming language to make it more
let's say that you in your new programming work your boss comes and says
What is the real benefit of creating a new programming language? It is highly

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.