C++/cli 我有一个问题,我的 std::list 是空的
C++/cli I'm having an issue that my std::list is empty
我的问题是,我试图将 3 个字符串保存在列表中以占据相同的位置,但由于某种原因它对我不起作用,我尝试使用向量而不是列表,但出现了同样的问题。我知道变量的输入是正确的,所以我不明白为什么它不能将值正确地推送到列表中。
这是我的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;
};
}
这是我的一部分 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();
}
这会将 windows 字符串转换为标准字符串
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);
}
如果您需要我展示完整的 Add_Job_Info.h,那么我会编辑 post,我只是不想 post 写太多代码[=] 14=]
正在替换
serviceOrderNumber = serviceOrder_Number;
有
serviceOrder_Number = 服务订单号;
已解决我的问题
感谢1201ProgramAlarm解决了我的问题
我的问题是,我试图将 3 个字符串保存在列表中以占据相同的位置,但由于某种原因它对我不起作用,我尝试使用向量而不是列表,但出现了同样的问题。我知道变量的输入是正确的,所以我不明白为什么它不能将值正确地推送到列表中。
这是我的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;
};
}
这是我的一部分 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();
}
这会将 windows 字符串转换为标准字符串
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);
}
如果您需要我展示完整的 Add_Job_Info.h,那么我会编辑 post,我只是不想 post 写太多代码[=] 14=]
正在替换 serviceOrderNumber = serviceOrder_Number;
有 serviceOrder_Number = 服务订单号;
已解决我的问题
感谢1201ProgramAlarm解决了我的问题