+ -
当前位置:首页 → 问答吧 → c#轉c++ 與c++ list的問題

c#轉c++ 與c++ list的問題

时间:2011-12-27

来源:互联网

C++ code:
//////GlobalCls.h裡的code://///
typedef struct struct_Lu
{
  int a;
  double x;
  double y;
  int z;  
}Lu;
class GlobalCls
  {
  public:
  list<Lu> listInfo;
  };
////////////////////////////////

////////from1.h的code///////////
GlobalCls.listInfo.x;

錯誤:error C2039: 'x' : 不是 'std::list<_Ty>' 的成員
////////////////////////////////

1.請問要如何取出單一值,如取x或y.
2.假設存好了3筆list 又如何取其中一個list裡的x

請求各位高手解答,這已經讓我撞牆很久了!! 謝謝.

作者: kranoawi   发布时间: 2011-12-27

Lu.x

作者: cbzjzsb123   发布时间: 2011-12-27

给你的程序参考,应该可以明白了
C/C++ code

#include <iostream>
#include <list>
using namespace std;
typedef struct struct_Lu
{
  int a;
  double x;
  double y;
  int z;   
}Lu;
class GlobalCls
  {
  public:
  list<Lu> listInfo;
  };
int main()
{
     Lu lu;
     lu.a=10;
     lu.x=123.45;
     lu.y=456.78;
     lu.z=100;
     
     
     GlobalCls test;
     test.listInfo.push_back(lu);  //添加一个数据
     
     lu.a=2;
     lu.x=223.45;
     lu.y=256.78;
     lu.z=200;
     
     test.listInfo.push_back(lu);  //添加第二个数据

     
     list<Lu>::iterator plist; 
      for(plist = test.listInfo.begin(); plist != test.listInfo.end(); plist++)  //取出数据
        cout << (*plist).a << " " <<(*plist).x <<endl; 

}


作者: keiy   发布时间: 2011-12-27