textbox text to std::string

Hello , i have automated calculator code made that takes values from syntax std::string
How could it be converted from textbox system string to std::string ?

Soft is visual c++ 2010.
For example

std::string A;
std::string A = textBox1->Text;// problem is here

What type is textBox1 ? What is the problem you have, i.e. what is the error number and description? Does the textBox1 have a function named Text or is it a variable, if the former then you need to add parenthesis; i.e. Text() We basically need more info.
Looks to me like you're using C++/CLI which is NOT C++. It is a completely different language created by Microsoft to supersede Managed Extensions for C++. (.NET)

http://en.wikipedia.org/wiki/C_/CLI

textBox1->Text is most likely of type System::String^ which is a managed object reference, not a normal string as you know it.
Yes it appers to be system string, i have programming experience counted in hours , dont know correct terminology.

input example would be "10+5-1" length differs

example of problem
1
2
std::string AAA;
AAA = textBox1->Text;

How to convert system string to std::string?
Use the marshal_as function:

http://msdn.microsoft.com/en-us/library/bb384865.aspx

Use std::string as the To_Type. Example:

http://msdn.microsoft.com/en-us/library/bb384859.aspx
q139,

Before you go to far I would like to discourage you from proceeding on this path.

Mixing C++ and C++/CLI is not for the faint hearted. I have never seen a beginner produce anything but a mess of unstable code. C++/CLI was also not intended to be a fully fledged language for use with Winforms.

Winforms has been dropped from the Visual C++ CLR templates list in Visual Studio 2012 and on. Microsoft s advise would seem to be if you want to do Windows Desktop UI code (with the .Net framework), use C# (or VB.NET).




Having said that; converting System::String^ to std::string...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "stdafx.h"
#include <string>

#include <msclr\marshal_cppstd.h>

using namespace System;

int main(array<System::String ^> ^args)
{
    System::String^ managedString = "test";

    msclr::interop::marshal_context context;
    std::string standardString = context.marshal_as<std::string>(managedString);

    return 0;
}
Last edited on
Thanks alot for decent example , finnaly got first app to work.

You are right , i generated hundreds of errors before code started to compile.


http://oi59.tinypic.com/2s8lngl.jpg

It starts to calculate if text changes
i was writing 100-200 line code to calculate row of numbers it but is it possible to calculate a string of numbers like "10+1-2*4" in single command?

visual basics made 1mb file for my short code calculator, What type of software i should use to try learn c++ , best if it has simple gui designing included that is compatable with std::string?
Last edited on
Topic archived. No new replies allowed.