本文介绍了将System :: String ^转换为std :: strings错误c1083包含文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
伙计们!
我正在这样做,看是否有一天我可以打印我的数组:
Hi, guys!
I''m doing this, to see if one day I can print my arrays:
// Case_2.cpp
//
#include <stdafx.h>
#include <string>
#include <iostream>
#include <fstream>
#include <istream>
#include "Form1.h"
#include <marshal_cppstd.h> // Also tried "marshal_cppstd.h"
using namespace Case_2;
//
int main ()
{
void save_arrays ();
return 0;
}
//
void save_arrays ()
{
array<String^>^ my_array = gcnew array<String^> {"xxx", "yyy", "zzz"};
for (int i = 0; i< 3; i++)
{
System::String^ clrString = my_array[i];
std::string stdString = marshal_as<std::string>(clrString);
std::cout << stdString << std::endl;
}
return;
}
有帮助吗?
ANY HELP?
推荐答案
#include "stdafx.h"
#include <string>
#include <iostream>
#include <fstream>
#include <istream>
#include <msclr\marshal.h>
using namespace System;
using namespace Runtime::InteropServices;
void save_arrays();
int main(array<System::String ^> ^args)
{
save_arrays();
return 0;
}
void save_arrays ()
{
array<String^>^ my_array = gcnew array<String^> {"xxx", "yyy", "zzz"};
for (int i = 0; i< 3; i++)
{
System::String^ clrString = my_array[i];
const char* chars = (const char*)(Marshal::StringToHGlobalAnsi(clrString)).ToPointer();
std::string stdString = chars;
std::cout << stdString << std::endl;
}
return;
}
这篇关于将System :: String ^转换为std :: strings错误c1083包含文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!