tags:

views:

758

answers:

3

I am working in Visual C++. I'm giving following command

String nodename[100];

but this command is giving the following error

"error : 'System::String' : a native array cannot contain this managed type"

So what should I do now ?

+3  A: 

If you want to write a native C++ application, then you can't, as the error says, use managed types.

That means you have to use the C++ string class,

#include <string> // at the top of the file
std::string nodename[100]; // where you want to declare the array

instead of System::String.

On the other hand, if you want to make a managed C++/CLI application, then you can't use native arrays. (But can use all the .NET types)

jalf
the above command gives the following error'std' : is not a class or namespace name
Then you didn't add the `#include` part properly. Put that at the very top of the file.
jalf
and it is string, not string.h
jalf
+3  A: 

You didn't say whether you want Managed C++, C++/CLI, or unmanaged C++

managed C++

http://www.codeproject.com/KB/mcpp/csarrays01.aspx

C++/CLI

http://www.codeproject.com/KB/mcpp/cppcliarrays.aspx

unmanaged C++ (standard C++)

std::string nodename[100]; // uses STL string, not .NET String

Lou Franco
i want to use unmanaged C++ std::string nodename[100];this command give following error even though i use #include"string.h" also'std' : is not a class or namespace name
#include <string>
Lou Franco
A: 

OK. First off it looks like you are using managed C++ (ick). Secondly, you are trying to declare an array of strings (not chars, but entire strings). Is that really what you want to do? Are you sure you don't want something like char nodename[100] or just String nodename?

If you really want an array of strings, it looks like the compiler either wants you to use one of its managed vector-like types to do it, or to use only unmanaged types to do it.

T.E.D.