Hi, Let me preface this by saying I'm about 4 days into learning MSVC++ 2010.
I just need a little program that takes in a string, puts it in an array and I'd really like it to display it on the screen as the data comes in (1089 strings per frame, about 30fps). But I'm starting small by building a little dynamic array, then hopefully displaying it via the datagridview?
I'm having some issues with the managed string versus standard string. I did try reading other forms, I guess I'm just not getting it. Here's what I have:
`

#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

//Blah blah blah

public: void makeDynamicStringArray(){

            System::String^ AnotherString;
            string lastEntry;
            vector<string> DynArrStrs (3);

            DynArrStrs[0] = "alpha";
            DynArrStrs[1] = "bravo";
            DynArrStrs[2] = "charlie";

            txtArraySize->Text = Convert::ToString(DynArrStrs.size());

            txtInputNum->Text = AnotherString;      
    //Convert mgd string to std string for .push_back()?

            DynArrStrs.push_back(AnotherString);
    //convert from std string to mgd string?
            txtArraySize->Text = Convert::ToString(DynArrStrs.size());

            lastEntry = DynArrStrs[DynArrStrs.size()-1];
            String^ managedlastEntry = gcnew String(lastEntry.c_str());
            txtLastEntry->Text = managedlastEntry;
            return 0;
     }

To which the compiler replies: error C2664: 'void std::vector<_Ty>::push_back(_Ty &&)' : cannot convert parameter 1 from 'System::String ^' to 'std::string &&'
So I'm guessing that .push_back() needs a std::string, while the textboxes need a System::String? I found this marshal conversion for strings I'm trying to get to work. Is there an easier/better/generic way to do this? Any advice is much appreciated! Thanks in advance!

You can't mix managed and unmanaged code like that. The program you wrote is NOT standard c++, but is CLI/C++ which is somewhat different. CLI/C++ is a .NET language, similir to C# and VB.NET. Fortunately, CLI/C++ has managed version of many standard c++ containers located in the cliext folder. You can not use std::string with any of the containers in cliext, so there is no point including <string> header file.

#include <cliext/vector>
using namespace cliext;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.