Search code examples
c++c++-clistdlist

C++/cli I'm having an issue that my std::list is empty


My problem is that I am trying to save 3 strings in a list to take the same place how ever it doesn't work for me for some reason, I have tried using vector instead of list but same issue appeared. I know for a fact that the variables have correct input so I don't understand why it wouldn't push the values to the list correctly.

This is my Lists.h

#pragma once
#include <list>
#include <string>
#include <iostream>

namespace JobStatus
{
using namespace System::Collections::Generic;
using namespace System::Text;
using namespace std;

class service_Order
{
private:
    string serviceOrder_Number;
    string serviceOrder_Status;
    string time_Stamp;

public:
    string GetserviceOrder_Number()
    {
        return serviceOrder_Number;
    }
    string SetserviceOrder_Number(string serviceOrderNumber)
    {
        serviceOrderNumber = serviceOrder_Number;
        return serviceOrderNumber;
    }

    string GetserviceOrder_Status()
    {
        return serviceOrder_Status;
    }
    string SetserviceOrder_Status(string serviceOrderStatus)
    {
        serviceOrderStatus = serviceOrder_Status;
        return serviceOrderStatus;
    }

    string Gettime_Stamp()
    {
        return time_Stamp;
    }
    string Settime_Stamp(string timeStamp)
    {
        timeStamp = time_Stamp;
        return timeStamp;
    }
};

class Lists
{
public:
    list<service_Order> service_Order_List;
};
}

This is part of my Add_Job_Info.h

 private: System::Void Add_Job_Click(System::Object^ sender, System::EventArgs^ e)
    {           
        //Gets SO number from the text box
        String^ service_order_number = Service_Order_Number->Text;
        ClrStringToStdString(serviceOrderNumber, service_order_number);

        //Gets SO status from the select box
        String^ service_order_status = Job_Status->Text;
        ClrStringToStdString(serviceOrderStatus, service_order_status);

        //Gets time from the system
        Time t;
        t.setTime();
        if (t.timeinfo.tm_min < 10)
        {
            String^ timestamp = (t.timeinfo.tm_hour + ":0" + t.timeinfo.tm_min);
            ClrStringToStdString(timeStamp, timestamp);
        }
        else
        {
            String^ timestamp = (t.timeinfo.tm_hour + ":" + t.timeinfo.tm_min);
            ClrStringToStdString(timeStamp, timestamp);
        }

        

        //Saves all of the above in a List
        newSO.SetserviceOrder_Number(serviceOrderNumber);
        newSO.SetserviceOrder_Status(serviceOrderStatus);
        newSO.Settime_Stamp(timeStamp);
        service_order_lists.service_Order_List.push_back(newSO);

        for each (newSO in service_order_lists.service_Order_List)
        {
            cout << serviceOrderNumber; //shows service order number correct
            cout << serviceOrderStatus; //shows service order status correct
            cout << timeStamp; //shows time stamp correctly
            cout << newSO.GetserviceOrder_Number() << ":" << newSO.Gettime_Stamp() << ":" << newSO.GetserviceOrder_Status(); //This returns only ::
        }

        this->Close();
    }

This converts windows String to std string

 static void ClrStringToStdString(string& outStr, String^ str) //Converts Windows managed Strings to std unmanaged strings
    {
        IntPtr ansiStr = Marshal::StringToHGlobalAnsi(str);
        outStr = (const char*)ansiStr.ToPointer();
        Marshal::FreeHGlobal(ansiStr);
    }

If you need me to show my full Add_Job_Info.h then I will edit the post, I just didn't want to annoy anyone by posting too much code


Solution

  • Replacing serviceOrderNumber = serviceOrder_Number;

    With serviceOrder_Number = serviceOrderNumber;

    Has fixed my issue

    Thanks to 1201ProgramAlarm for solving my problem.