如何在C ++中使用列表数组 [英] How to use list array in C++
本文介绍了如何在C ++中使用列表数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从sqlite3数据库中获取品牌列表,你可以在BrandCodes函数中看到,我已经编写了新函数Brands(),我不知道如何将BRCode和BRText分配给这个结果。这是正确的方法吗?伙计们,请帮助我。我知道如何在C#中使用。
SortedList * Util :: BrandCodes()
{
SortedList * list = new SortedList();
IDbCommand * command = 0 ;
IDataReader * reader = 0 ;
command = m_dbConnection-> CreateCommand();
command-> CommandText = S SELECT * FROM BrandData;
reader = command-> ExecuteReader();
// 阅读所有记录
while (reader-> Read())
{
// 将项目添加到地图[market_id,description]
list-> Add(reader-> Item [S BRCode] - > ToString(),
字符串 ::格式(S {0}({1}),GetFieldValue(reader,S BRText),GetFieldValue(reader,S BRCode跨度>)));
}
品牌();
返回列表;
}
字符串 * FuelUtil :: Brands() __ gc []
{
字符串 *结果 __ gc [];
result = 0 ;
SortedList * brandList = 0 ;
if (brandList == 0 )
{
brandList = GetBrandCodes();
}
for ( int i = 0 ; i< = brandList-> Count; i ++)
{
result = new < span class =code-sdkkeyword> String * __ gc [ 2 ];
// 如何将BRCode和BRText分配给此结果
// result [0] =
// result [1] =
}
return 结果;
}
我的尝试:
我试过这种方式
String * FuelUtil :: Brands() __ gc []
{
String * result < span class =code-keyword> __ gc [];
result = 0 ;
SortedList * brandList = 0 ;
if (brandList == 0 )
{
brandList = GetBrandCodes();
}
for ( int i = 0 ; i< = brandList-> Count; i ++)
{
result = new < span class =code-sdkkeyword> String * __ gc [ 2 ];
// 如何将BRCode和BRText分配给此结果
// result [0] =
// result [1] =
}
return 结果;
}
解决方案
首先,我不确定你是否正确行事。
看起来你正在使用托管C ++,在这种情况下你应该使用SortedList ^
而不是SortedList *
和也gcnew
而不是new
。
你应该能够使用 -brandList->值[i];
获取for循环中的值这当然会返回一个字符串格式BRText(BRCode)
就像你插入列表一样。
然后你需要拆分使用 String :: Split Method(array< char> ^)将它分成单独的字符串 [ ^ ]。
I am getting the list of brands from sqlite3 database,you can see in BrandCodes function, I have written new function Brands(), I don't know how to assign BRCode and BRText to this result. Is this the right approach. Please help me, guys. I know how to use in C#.
SortedList *Util::BrandCodes()
{
SortedList *list = new SortedList();
IDbCommand *command = 0;
IDataReader *reader = 0;
command = m_dbConnection->CreateCommand();
command->CommandText = S"SELECT * FROM BrandData";
reader = command->ExecuteReader();
// Read all records
while( reader->Read() )
{
// Add item to the map [ market_id, description ]
list->Add( reader->Item[ S"BRCode" ]->ToString(),
String::Format(S"{0}({1})",GetFieldValue(reader,S"BRText"),GetFieldValue(reader,S"BRCode")));
}
Brands();
return list;
}
String *FuelUtil::Brands( ) __gc[]
{
String *result __gc[];
result = 0;
SortedList *brandList = 0;
if (brandList == 0)
{
brandList = GetBrandCodes();
}
for (int i =0; i<= brandList->Count; i++)
{
result = new String * __gc[2];
// how to assign BRCode and BRText to this result
//result[0] =
//result[1] =
}
return result;
}
What I have tried:
I tried this way
String *FuelUtil::Brands( ) __gc[]
{
String *result __gc[];
result = 0;
SortedList *brandList = 0;
if (brandList == 0)
{
brandList = GetBrandCodes();
}
for (int i =0; i<= brandList->Count; i++)
{
result = new String * __gc[2];
// how to assign BRCode and BRText to this result
//result[0] =
//result[1] =
}
return result;
}
解决方案
Fistly, I'm not sure if you're doing this right.
Looks like you're using managed C++ in which case you should be usingSortedList^
instead ofSortedList*
and alsogcnew
instead ofnew
.
You should be able to get the value inside the for loop using -brandList->Values[i];
This would of course return a string in the format"BRText(BRCode)"
like you inserted into the list.
You will then need to split it into separate strings using String::Split Method (array<char>^)[^].
这篇关于如何在C ++中使用列表数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文