【问题标题】:Converting textbox->text to string将文本框->文本转换为字符串
【发布时间】:2017-11-21 12:22:01
【问题描述】:

嘿,我正在尝试将在文本框中输入的文本保存为字符串

#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]));
}

但是我收到了这些错误,怎么了?如何将文本框中的输入保留为字符串以供将来使用,或者有更好的方法来保留文本输入以供将来使用?

错误 1 ​​错误 C2679:二进制“=”:未找到采用“System::String ^”类型右侧操作数的运算符(或没有可接受的转换)

错误 2 错误 C2665: 'System::Convert::ToString' : 37 个重载中没有一个可以转换所有参数类型

3 IntelliSense:没有运算符“=”与这些操作数匹配 操作数类型为:std::string = System::String ^

4 IntelliSense:没有重载函数“System::Convert::ToString”的实例与参数列表匹配 参数类型是:(std::string)

【问题讨论】:

  • This 可能会对您有所帮助。
  • 1.这是 C++/CLI,而不是 C++。为什么要混合托管和非托管代码? std::stringSystem.String 是不同的类型,可能更容易选择并使用它。

标签: string text textbox c++-cli


【解决方案1】:

你在混淆你的类型。声明

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

作为

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

你的问题在这里消失了。也许你的代码的其他部分会出现问题,但你还没有发布那些......

【讨论】:

  • System::String^ TabOdpowiedzi[10][6]; 的良好定义会产生这些错误:Error 1 error C2728: 'System::String ^' : a native array cannot contain this type 2 IntelliSense: array of handles is not allowed
  • 对不起,你是对的,你可以找到 C++/CLI here 的正确语法。
猜你喜欢
  • 1970-01-01
  • 2015-10-03
  • 2018-05-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-08
  • 2011-02-03
  • 2011-05-06
相关资源
最近更新 更多