CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 20

Threaded View

  1. #4
    Join Date
    Apr 1999
    Posts
    27,449

    Re: PHP array in C++ ?

    Quote Originally Posted by ArdentAngel View Post
    Oh, and the models array should having this kind of values:
    PHP Code:
    $models['object1']['x'] = 7831;
    $models['object2']['x'] = 1893
    To add to SMA's example:
    Code:
    #include <map>
    #include <string>
    #include <iostream>
    
    template <typename T>
    struct Point
    {
        T x;
        T y;
        T z;
        Point(T theX = T(), T theY = T(), T theZ = T()) : x(theX), y(theY), z(theZ) {}
    };
    
    typedef std::map<std::string, Point<double> > FloatModels;
    typedef std::map<std::string, Point<int> >      IntModels;
    
    using namespace std;
    
    int main()
    {
        FloatModels models;
        IntModels models2;
        models["object1"] = Point<double>();  // defaults to 0.0
        models["object2"] = Point<double>(3.0, 2.0, -1.9);
    
        models2["object1"] = Point<int>();  // defaults to 0
        models2["object2"] = Point<int>(3, 2, -1);
    
        cout << "Here are the floating point coordinates:\n";
        FloatModels::iterator it = models.begin();
        while (it != models.end() )
        {
            cout << it->first << " -> " << "(" << it->second.x << ", " << it->second.y << ", " << it->second.z << ")\n";
            ++it;
        }
    
        cout << "\nHere are the integer point coordinates:\n";
        IntModels::iterator it2 = models2.begin();
        while (it2 != models2.end() )
        {
            cout << it2->first << " -> " << "(" << it2->second.x << ", " << it2->second.y << ", " << it2->second.z << ")\n";
            ++it2;
        }
    }
    
    Output:
    Here are the floating point coordinates:
    object1 -> (0, 0, 0)
    object2 -> (3, 2, -1.9)
    
    Here are the integer point coordinates:
    object1 -> (0, 0, 0)
    object2 -> (3, 2, -1)
    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; October 10th, 2012 at 06:50 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured