System :: String for basic_string

0

I was looking to convert System :: String to "normal" string, and found a command:

#include <iostream>
#include <string>
#include <msclr\marshal_cppstd.h>
System::String^ mstr = "PTSO";
std::string mstrr msclr::interop::marshal_as< string >(mstr);

It worked, but I tried to do a function to "ease" the use, and I could not. I tried this way:

#include <iostream>
#include <string>
#include <msclr\marshal_cppstd.h>
string SysStrToStr(System::String^ sstr) {
        return msclr::interop::marshal_as< std::string >(sstr);
    }

You gave this error:

1>Source.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __clrcall SysStrToStr(class System::String ^)" (?SysStrToStr@@YM?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@P$AAVString@System@@@Z) already defined in MyForm.obj

Clarifying: I am trying to create a new class in a Visual Studio 2008 application. I am using Visual Studio 2008 and I want to create a new class in Visual Studio 2008. :: string) to use.

    
asked by anonymous 23.12.2014 / 02:03

0 answers