Why can't I declare a string in my program: “string is undeclared identifier”

前端 未结 3 1103
粉色の甜心
粉色の甜心 2021-01-12 07:12

I can\'t declare a string in my program:

string MessageBoxText = CharNameTextBox->Text;

it just doesn\'t work. It says string is u

3条回答
  •  囚心锁ツ
    2021-01-12 07:58

    Make sure you've included this header:

    #include 
    

    And then use std::string instead of string. It is because string is defined in std namespace.

    And don't write this at namespace scope:

    using namespace std; //bad practice if you write this at namespace scope
    

    However, writing it at function scope is not that bad. But the best is one which I suggested before:

    Use std::string as:

    std::string MessageBoxText = CharNameTextBox->Text;
    

提交回复
热议问题