1

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)

2
  • This might help you. Commented Nov 21, 2017 at 12:30
  • 1. This is C++/CLI, not C++. Why are you mixing managed and unmanaged code? std::string and System.String are different types, it's propably easier to pick one and use it. Commented Nov 21, 2017 at 12:31

1 Answer 1

1

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...

Sign up to request clarification or add additional context in comments.

2 Comments

Well definition of System::String^ TabOdpowiedzi[10][6]; generates those errors: Error 1 error C2728: 'System::String ^' : a native array cannot contain this type 2 IntelliSense: array of handles is not allowed
Ah sorry, you are right, you can find the correct syntax for C++/CLI here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.