0
这是我从代码中读取文件的结构。如何从我的结构数组中删除重复项?
int _tmain(int argc, _TCHAR* argv[])
{
typedef struct
{
char name_1[100];
char Max_1[100];
char Min_1[100];
} power_line_name;
int numLines;
StreamReader^sr1=File::OpenText("testcpp\\test\\powerline.txt");
while(sr1->ReadLine())
{
numLines++;
}
power_line_name* power_list=new power_line_name[numLines];
//power_line_name power_list[5];
StreamReader^sr=File::OpenText("testcpp\\test\\powerline.txt");
array<System::String ^> ^power_line;
array<System::String ^> ^d_line;
String^eachString;
String^eachString_2;
String^eachString_3;
int i=0;
char nstring[100];
try
{
String^ s="";
while (s=sr->ReadLine())
{
power_line=s->Split(':');
Console::WriteLine(s);
d_line=power_line[1]->Split('|');
for(int a=0;a<d_line->Length;a++)
{
pin_ptr<const wchar_t> wch = PtrToStringChars(d_line[a]);
size_t origsize = wcslen(wch) + 1;
size_t convertedChars = 0;
if(a==0)
{
wcstombs_s(&convertedChars, power_list[i].name_1, origsize, wch, _TRUNCATE);
strcat_s(power_list[i].name_1, " (char *)");
}
if(a==1)
{
wcstombs_s(&convertedChars, power_list[i].Max_1, origsize, wch, _TRUNCATE);
strcat_s(power_list[i].Max_1, " (char *)");
}
if(a==2)
{
wcstombs_s(&convertedChars, power_list[i].Min_1, origsize, wch, _TRUNCATE);
strcat_s(power_list[i].Min_1, " (char *)");
}
}
i++;
}
Console::WriteLine(s);
}
finally
{
if(sr)
delete (IDisposable^)(sr);
}
return 0;
}
下面是其输出:
power_list[0].name_1=aaaa power_list[0].Max_1=1111111 power_list[0].Min_1=222222 power_list[1].name_1=aaaa power_list[1].Max_1=333333 power_list[1].Min_1=444444 power_list[2].name_1=aaaa power_list[2].Max_1=333333 power_list[2].Min_1=444444 power_list[3].name_1=aaaa power_list[3].Max_1=33333 power_list[3].Min_1=66666
如果Max_1
和Min_1
对于一些两个元件是相同的,我想要删除的第二元件。
所以新的输出继电器将是:
power_list[0].name_1=aaaa power_list[0].Max_1=1111111 power_list[0].Min_1=222222 power_list[1].name_1=aaaa power_list[1].Max_1=333333 power_list[1].Min_1=444444 power_list[2].name_1=aaaa power_list[2].Max_1=33333 power_list[2].Min_1=66666
我不知道该怎么办?
C++标准库有许多很好的[算法函数](http://en.cppreference.com/w/cpp/algorithm)内置的,例如[删除重复项](http://en.cppreference .COM/W/CPP /算法/唯一的)。尽管对于C++ CLI,您应该搜索[MSDN](http://msdn.microsoft.com/)以获取相应的信息。 –
此代码看起来像CLI/.Net。 – vz0