Daniel Zietek
Daniel Zietek

Reputation: 35

Converting textbox->text to string

Hey I'm trying to save text entered in textbox as string

#pragma once
#include <iostream>
#include <string>

namespace Project1 {

    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;


    int IloscBD1=0, IloscBD2=0, IloscPD1, IloscPD2, Suma, I, J, Punkty, P1, P2, P3, P4, P5, P6, Druzyna;
    int TabPunkt[10][6];

    std::string TabOdpowiedzi[10][6];

...


...
private: System::Void buttonZ_Click(System::Object^  sender, System::EventArgs^  e) {
    TabOdpowiedzi[1][1] = (Convert::ToString(textPO->Text));
    this->textPN->Text = (Convert::ToString(TabOdpowiedzi[1][1]));
}

But I am getting those errors, what's wrong? How can I keep input from text box as a string for future or is there a better way to keeping text input for future usage ?

Error 1 error C2679: binary '=' : no operator found which takes a right-hand operand of type 'System::String ^' (or there is no acceptable conversion)

Error 2 error C2665: 'System::Convert::ToString' : none of the 37 overloads could convert all the argument types

3 IntelliSense: no operator "=" matches these operands operand types are: std::string = System::String ^

4 IntelliSense: no instance of overloaded function "System::Convert::ToString" matches the argument list argument types are: (std::string)

Upvotes: 1

Views: 870

Answers (1)

nvoigt
nvoigt

Reputation: 77294

You are mixing up your types. Declare

std::string TabOdpowiedzi[10][6];

As

array<System::String^,2>^ TabOdpowiedzi = gcnew array<System::String^,2>(10, 6);

And your problems here vanish. Maybe you will have problems in other parts of your code then, but you have not posted those...

Upvotes: 1

Related Questions