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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:09:21+00:00 2026-05-24T05:09:21+00:00

So I am having an issue within the two methods posted below. Aside from

  • 0

So I am having an issue within the two methods posted below. Aside from terrible naming of variables, I only have one problem. Somehow between getData and cutRamping, my vector TwoDee disappears. I have traced it using gdb, and at the end of getData it is filled with values, but when I try to trace it manually or the program tries to use it in cutRamping it throws a segfault relating to the iterator in the vector, and when I tell gdb to print the vector, it prints 0x0 instead of a valid memory address. These two methods are literally called back to back, so I don’t know how I could be losing the data in the vector TwoDee without me calling any methods that would do that. Any help would be appreciated!

header file:

class Deviation
{
public:
    Deviation();
    void graphDev(std::string infile, std::string outfile1, std::string outfile2, std::vector<double> plats);

private:
    void getData();
    void cutRamping();
    void calcDev();
    void makeGraph();

    std::string input, output1, output2;
    std::vector<double> current, dx, dy, gcurrent, gdx, gdy, gdevx, gdevy, tempcurrent, tempdx, tempdy, plateaus;
    std::vector< std::vector<double> > TwoDee, FileOut, FileOutTemp; // File Out is a 2-D array that holds the Strength, b3-6 and a3-6 that are to be written to the file in that order where the Temp just holds each plateau value
    std::vector<double> curRow;
};

cpp file:

void Deviation::getData()
{
    float f;
    vector< vector<float> > TwoDee;
    vector <float> curRow;
    TwoDee.clear();
    curRow.clear();
    FILE * pFile;
    ifstream inFile(input.c_str());
    // Counts the number of lines in the file
    unsigned int lines = count(istreambuf_iterator<char>(inFile), istreambuf_iterator<char>(), '\n');
    inFile.close();
    pFile = fopen (input.c_str(),"r");
    // Pushes all of the data into a 2-D vector
    for (unsigned int j = 0; j<lines; j++)
    {
        for (unsigned int i = 0; i<37; i++)
        {
            fscanf (pFile, "%f", &f);
            curRow.push_back((double)f);
            // Just says that it pushed back a value
            //cout<<"just pushed back "<<f<<endl;
        }
        TwoDee.push_back(curRow);
        curRow.clear();
    }

    fclose (pFile);

    for (unsigned int i = 0; i<TwoDee[0].size(); i++)
    {
        current.push_back(TwoDee[1][i]);
        dx.push_back(TwoDee[4][i]);
        dy.push_back(TwoDee[5][i]);
    }
}

void Deviation::cutRamping()
{
    // Moved these out of the loop for now
    tempcurrent.clear();
    tempdx.clear();
    tempdy.clear();
    unsigned int i = 0;
    bool keepgoing = true;
    for (unsigned int j = 0; j<plateaus.size(); j++)
    {
        keepgoing = true;
        while (i<current.size()&&keepgoing)
        {
            if (fabs(plateaus[j]-current[i]) < 0.2 && i<current.size()) // (0.2 is the tolerance to determine if the current is ramping or not)
            {
                tempcurrent.push_back(current[i]);
                tempdx.push_back(dx[i]);
                tempdy.push_back(dy[i]);
                FileOutTemp[0].push_back(TwoDee[3][i]);

    // ...
    // Rest of the method that never gets called
}
  • 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-24T05:09:23+00:00Added an answer on May 24, 2026 at 5:09 am

    The vector in getData is “shadowing” (hiding) the vector in your class, and then when getData exits, all the contents of the vector are freed. You should probably just not redeclare it in the method.

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

Sidebar

Related Questions

I am having an issue where I have two forms on the one page
I'm having an issue calling a method from a separate project within the same
I'm having a weird issue with a function I'm trying to call from within
I'm having an issue with accessing objects within two different instances of the SPSite
I'm having a strange issue with image captures from OpenGL on iOS. I have
I'm having an issue with expressions within reports. I'm coloring the background of a
Having issues referencing $(this) from within a the nested ajax 'success' function... I know
Having an issue here that I have tried everything I can think of but
I'm working on a navigation-based iPhone-only app that serves two main purposes: One, to
I am having an issue with a string manipulation method I have written. The

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.