本文介绍了Visual C ++ 2010字符串变量&阵列错误C2728的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
伙计们!抱歉再次打扰您.
我在最简单的事情上遇到了麻烦:字符串变量和数组.任何帮助将不胜感激.
1)这是我的代码:
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:
// 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)这是错误:
3) Here''s the error:
error C2728: 'System::String ^' : a native array cannot contain this managed type.
推荐答案
array<string^>^ muniLara = gcnew array<string^>(9) {
"Andre", "Crespo", "Iribarren",
"Jimenez", "Moran", "Palaveccino", "Simon Planas",
"Torres", "Urdaneta"};
您可能会发现此CodeProject文章很有用:
C ++/CLI中的数组 [ ^ ].
You may find this CodeProject article useful:
Arrays in C++/CLI[^].
这篇关于Visual C ++ 2010字符串变量&阵列错误C2728的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!