Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, guys! Sorry to bother you again.

I'm having trouble with the simplest of things: string variables and arrays. Any help will be appreciated.

1) Here's my code:
C++
// CASE_2.cpp
#include <stdafx.h>
#include <string>
#include "Form1.h"
using namespace CASE_2;
int main ()
{
   void save_arrays ();
   CASE_2::Application::EnableVisualStyles();
   CASE_2::Application::SetCompatibleTextRenderingDefault(false);
   CASE_2::Application::Run(gcnew Form1());
return 0;
}
//
void save_arrays ()
{
   String^ m_path = "c\\wlo\\sipsi\\";
   String^ m_file = "muni_lara.arr";
   String^ m_filename  = m_path + m_file;   

   //2) Here's the source of error:
 
   String^ muni_lara[] = {"Andre", "Crespo", "Iribarren",
                       "Jimenez", "Moran", "Palaveccino", "Simon Planas",
                       "Torres", "Urdaneta"};
}
return;

3) Here's the error:
error C2728: 'System::String ^' : a native array cannot contain this managed type.
Posted
Updated 29-Feb-12 10:16am
v3
Comments
André Kraak 29-Feb-12 16:16pm    
Edited question:
Added pre tags
"Treat my content as plain text..." option disabled.

1 solution

You need to create C++/CLI (managed) array, for example:
C++
array<string^>^ muniLara = gcnew array<string^>(9) {
	"Andre", "Crespo", "Iribarren",
        "Jimenez", "Moran", "Palaveccino", "Simon Planas",
        "Torres", "Urdaneta"};

You may find this CodeProject article useful:
Arrays in C++/CLI[^].

—SA
 
Share this answer
 
v3
Comments
Wilmer Lameda 1-Mar-12 2:24am    
THANK YOU. I have no formal training on C++ and this is a whole new world for me. Still learning. I don't post questions before researching the topic, but I have no one near to ask. Thanks again.
Sergey Alexandrovich Kryukov 1-Mar-12 3:25am    
You are very welcome.

(But who has the "formal training"? We need education, not training. We all can "train" ourselves, you too. Keep learning...)

Good luck, call again.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900