甩浆规范:error C2440: 'initializing' : cannot convert from 'std::string' to 'System::String ^'
来源:百度文库 编辑:中科新闻网 时间:2024/05/15 02:18:39
#using <System.dll>
#include <iostream>
#include <string>
using namespace std;
using namespace System;
using namespace System::Text::RegularExpressions;
int main()
{
Regex^ rx = gcnew Regex("^[A-Za-z0-9]+$");
//单独用下面一句时,没有错误
array<String^>^tests = {"42","ab"};
//当用一下三句来替代上面一 句时,出现如标题一样的错误
string str1="42";
string str2="ab";
array<String^>^tests = {str1,str2};
System::Collections::IEnumerator^ myEnum = tests->GetEnumerator();
while ( myEnum->MoveNext() )
{
String^ test = safe_cast<String^>(myEnum->Current);
if ( rx->IsMatch( test ) )
{
Console::WriteLine( "{0} is a currency value.", test );
}
else
{
Console::WriteLine( "{0} is not a currency value.", test );
}
}
system ("pause");
}
不是高手,只要明白的人,请指点一下,小魔在此谢过。
请问怎么才能统一类型啊?
#include <iostream>
#include <string>
using namespace std;
using namespace System;
using namespace System::Text::RegularExpressions;
int main()
{
Regex^ rx = gcnew Regex("^[A-Za-z0-9]+$");
//单独用下面一句时,没有错误
array<String^>^tests = {"42","ab"};
//当用一下三句来替代上面一 句时,出现如标题一样的错误
string str1="42";
string str2="ab";
array<String^>^tests = {str1,str2};
System::Collections::IEnumerator^ myEnum = tests->GetEnumerator();
while ( myEnum->MoveNext() )
{
String^ test = safe_cast<String^>(myEnum->Current);
if ( rx->IsMatch( test ) )
{
Console::WriteLine( "{0} is a currency value.", test );
}
else
{
Console::WriteLine( "{0} is not a currency value.", test );
}
}
system ("pause");
}
不是高手,只要明白的人,请指点一下,小魔在此谢过。
请问怎么才能统一类型啊?
string str1="42";
string str2="ab";
array<String^>^tests = {str1,str2};
你 str1 和 str2 是 string 类型的,即 std::string 类型
而下面的 tests 是 String 类型的数组,即 System::String 类型
它们是两种类型,你需要统一一下。
error C2440: 'initializing' : cannot convert from 'std::string' to 'System::String ^'
Server Error in '/' Application.
Server Error in '/' Application.是什么意思?
Server Error in '/' Application错误
Server Error in '/' Application 怎么回事
server error in'/innerpage'application
Error in allocating coeffs in wave_allocate_wv
the error code in 4
Error in setting up help
your code put in Error