String C2143系统字符串错误

String C2143系统字符串错误,string,c++-cli,String,C++ Cli,所以互联网上说这个错误意味着我错过了一次机会;在某个地方,但据我所知,我没有那个错误。该代码应该询问用户是否想要添加单词,即使它已经在列表中,然后相应地响应输入。我是普通的C++,但GUI新手,所以我不熟悉所有的系统关键字。我正在使用VisualStudio2010。我将为您提供包含错误和头文件的代码。 这是我的AddName.h,在我初始化消息的第157行有错误C2143 #pragma once #include "Generator.h" #include <

所以互联网上说这个错误意味着我错过了一次机会;在某个地方,但据我所知,我没有那个错误。该代码应该询问用户是否想要添加单词,即使它已经在列表中,然后相应地响应输入。我是普通的C++,但GUI新手,所以我不熟悉所有的系统关键字。我正在使用VisualStudio2010。我将为您提供包含错误和头文件的代码。 这是我的AddName.h,在我初始化消息的第157行有错误C2143

    #pragma once
    #include "Generator.h"
    #include <msclr/marshal_cppstd.h>

    namespace GUI_PackProject {

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

    /// <summary>
    /// Summary for AddName
    /// </summary>
    public ref class AddName : public System::Windows::Forms::Form
    {
    public:
        AddName(void)
        {
            InitializeComponent();
            //
            //TODO: Add the constructor code here
            //
        }

    protected:
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        ~AddName()
        {
            if (components)
            {
                delete components;
            }
        }
    private: System::Windows::Forms::CheckBox^  FNCheckBox;
    private: System::Windows::Forms::CheckBox^  LNCheckBox;
    private: System::Windows::Forms::TextBox^  NameInput;
    protected: 


    internal: System::Windows::Forms::Label^  UserInstruction;
    private: System::Windows::Forms::Button^  btnAdd;
    internal: 
    private: 

    protected: 

    private:
        /// <summary>
        /// Required designer variable.
        /// </summary>
        System::ComponentModel::Container ^components;

    #pragma region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        void InitializeComponent(void)
        {
            this->FNCheckBox = (gcnew System::Windows::Forms::CheckBox());
            this->LNCheckBox = (gcnew System::Windows::Forms::CheckBox());
            this->NameInput = (gcnew System::Windows::Forms::TextBox());
            this->UserInstruction = (gcnew System::Windows::Forms::Label());
            this->btnAdd = (gcnew System::Windows::Forms::Button());
            this->SuspendLayout();
            // 
            // FNCheckBox
            // 
            this->FNCheckBox->AutoSize = true;
            this->FNCheckBox->Location = System::Drawing::Point(122, 83);
            this->FNCheckBox->Name = L"FNCheckBox";
            this->FNCheckBox->Size = System::Drawing::Size(76, 17);
            this->FNCheckBox->TabIndex = 0;
            this->FNCheckBox->Text = L"First Name";
            this->FNCheckBox->UseVisualStyleBackColor = true;
            // 
            // LNCheckBox
            // 
            this->LNCheckBox->AutoSize = true;
            this->LNCheckBox->Location = System::Drawing::Point(121, 106);
            this->LNCheckBox->Name = L"LNCheckBox";
            this->LNCheckBox->Size = System::Drawing::Size(77, 17);
            this->LNCheckBox->TabIndex = 1;
            this->LNCheckBox->Text = L"Last Name";
            this->LNCheckBox->UseVisualStyleBackColor = true;
            // 
            // NameInput
            // 
            this->NameInput->Location = System::Drawing::Point(122, 57);
            this->NameInput->Name = L"NameInput";
            this->NameInput->Size = System::Drawing::Size(100, 20);
            this->NameInput->TabIndex = 2;
            // 
            // UserInstruction
            // 
            this->UserInstruction->AutoSize = true;
            this->UserInstruction->Location = System::Drawing::Point(53, 60);
            this->UserInstruction->Name = L"UserInstruction";
            this->UserInstruction->Size = System::Drawing::Size(63, 13);
            this->UserInstruction->TabIndex = 3;
            this->UserInstruction->Text = L"New Name:";
            // 
            // btnAdd
            // 
            this->btnAdd->Location = System::Drawing::Point(104, 149);
            this->btnAdd->Name = L"btnAdd";
            this->btnAdd->Size = System::Drawing::Size(75, 23);
            this->btnAdd->TabIndex = 4;
            this->btnAdd->Text = L"Add!";
            this->btnAdd->UseVisualStyleBackColor = true;
            this->btnAdd->Click += gcnew System::EventHandler(this, &AddName::btnAdd_Click);
            // 
            // AddName
            // 
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(284, 262);
            this->Controls->Add(this->btnAdd);
            this->Controls->Add(this->UserInstruction);
            this->Controls->Add(this->NameInput);
            this->Controls->Add(this->LNCheckBox);
            this->Controls->Add(this->FNCheckBox);
            this->Name = L"AddName";
            this->Text = L"AddName";
            this->ResumeLayout(false);
            this->PerformLayout();

        }
    #pragma endregion
    private: System::Void btnAdd_Click(System::Object^  sender, System::EventArgs^  e) 
             {
                 bool warned = false;
                 int duptimes1 = 0;
                 int duptimes2 = 0;
                 String^ Name = NameInput -> Text;
                 string name = marshal_as<std::string>(Name);
                 Generator Pack_Names ("FirstNames.txt", "LastNames.txt");
                 if (String::IsNullOrEmpty(NameInput->Text))
                 {
                     MessageBox::Show("Please Enter in a Name to Input!");
                 }
                 else if (!FNCheckBox-> Checked && !LNCheckBox-> Checked)
                 {
                     MessageBox::Show("Please Check One or Both Boxes.");
                 }
                 //add first or last name to the list, including set-ups for duplicates
                 System::Windows::Forms::DialogResult result;
                 duptimes1 = Pack_Names.CheckDupps(name, 1);
                 duptimes2 = Pack_Names.CheckDupps(name, 2);
                 String^ message = "That name is already in First Names " + duptimes1 + " times and Last Names " + duptimes2 " . Would you like to add it anyways?";
                 if (FNCheckBox-> Checked)
                 {
                     if (duptimes1 > 0)
         {
                         result = MessageBox::Show(message, "Multiple Name Error", MessageBoxButtons::YesNo, MessageBoxIcon::Question);
                         warned = true;
                         if (result == System::Windows::Forms::DialogResult::Yes)
                         {
                             Pack_Names.Add(name, 1); //adds name to list 1
                         }
                         else if (result == System::Windows::Forms::DialogResult::No)
                         {
                             //close the window
                         }
                     }
                     else
                     {
                         Pack_Names.Add(name, 1);
                     }
                 }
                 if (LNCheckBox->Checked)
                 {
                     if (duptimes2 > 0 && warned == false)
                     {
                         result = MessageBox::Show(message, "Multiple Name Error", MessageBoxButtons::YesNo, MessageBoxIcon::Question);
                         warned = true;
                         if (result == System::Windows::Forms::DialogResult::Yes)
                         {
                             Pack_Names.Add(name, 2); //adds name to list 2
                         }
                         else if (result == System::Windows::Forms::DialogResult::No)
                         {
                             //close the window
                         }
                     }
                     else
                     {
                         Pack_Names.Add(name, 2);
                     }
                 }
                 //close the window

             }//End btnAdd
    };
    }
# Generator.h file #
     #pragma once
     #include <string>
     #include <iostream>
     #include <vector>
     #include <iostream>
     #include <fstream>
     #include <ctime>
     #include "StdAfx.h"
     using namespace std;

    class Generator
    {
    public:
    Generator(string file_name1, string file_name2);
    ~Generator();
    void Delete(string word, int list);
    int CheckDupps(string word, int list);
    int FindName(string word, int list);
    void Scramble(int list, int times);
    void Show(int number);
    void Add(string word, int list);
    string GetFullName(int number);
    void Save1(string file_name);
    void Save2(string file_name);
    string GetName(int place, int list);
    int GetSize(int list);
    void ChangeName(int list, int place, string new_name);
    void Update();
    private:
    vector <string> First;
    vector <string> Last;
    string FileName1;
    string FileName2;
    };
#pragma一次
#包括“发电机.h”
#包括
名称空间GUI_PackProject{
使用名称空间系统;
使用名称空间System::ComponentModel;
使用名称空间系统::集合;
使用命名空间System::Windows::Forms;
使用名称空间System::Data;
使用名称空间系统::绘图;
使用名称空间msclr::interop;
/// 
///AddName的摘要
/// 
public ref类AddName:public System::Windows::Forms::Form
{
公众:
AddName(无效)
{
初始化组件();
//
//TODO:在此处添加构造函数代码
//
}
受保护的:
/// 
///清理所有正在使用的资源。
/// 
~AddName()
{
if(组件)
{
删除组件;
}
}
私有:系统::Windows::窗体::复选框^FNCheckBox;
private:System::Windows::Forms::CheckBox^LNCheckBox;
私有:系统::Windows::窗体::文本框^NameInput;
受保护的:
内部:系统::Windows::窗体::标签^UserInstruction;
私有:系统::Windows::窗体::按钮^btnAdd;
内部:
私人:
受保护的:
私人:
/// 
///必需的设计器变量。
/// 
系统::组件模型::容器^组件;
#pragma区域Windows窗体设计器生成的代码
/// 
///设计器支持所需的方法-不修改
///此方法的内容与代码编辑器一起使用。
/// 
void初始化组件(void)
{
这->FNCheckBox=(gcnewsystem::Windows::Forms::CheckBox());
此->LNCheckBox=(gcnew System::Windows::Forms::CheckBox());
此->名称输入=(gcnew System::Windows::Forms::TextBox());
这->用户指令=(gcnew System::Windows::Forms::Label());
这->btnAdd=(gcnewsystem::Windows::Forms::Button());
此->SuspendLayout();
// 
//FNCheckBox
// 
此->FNCheckBox->自动调整大小=true;
此->FNCheckBox->位置=系统::绘图::点(122,83);
此->FNCheckBox->Name=L“FNCheckBox”;
此->FNCheckBox->尺寸=系统::图纸::尺寸(76,17);
此->FNCheckBox->TabIndex=0;
此->FNCheckBox->Text=L“名字”;
此->FNCheckBox->UseVisualStyleBackColor=true;
// 
//LNCheckBox
// 
此->LN复选框->自动调整大小=真;
此->LNCheckBox->位置=系统::绘图::点(121106);
此->LNCheckBox->Name=L“LNCheckBox”;
此->LNCheckBox->尺寸=系统::图纸::尺寸(77,17);
此->LNCheckBox->TabIndex=1;
此->LN复选框->文本=L“姓氏”;
此->LNCheckBox->UseVisualStyleBackColor=true;
// 
//名称输入
// 
此->名称输入->位置=系统::图形::点(122,57);
此->名称输入->名称=L“名称输入”;
此->名称输入->尺寸=系统::图纸::尺寸(100,20);
此->名称输入->选项卡索引=2;
// 
//用户指令
// 
此->用户指令->自动调整大小=真;
此->用户说明->位置=系统::绘图::点(53,60);
此->用户指令->名称=L“用户指令”;
这->用户指令->尺寸=系统::图纸::尺寸(63,13);
此->用户指令->选项卡索引=3;
此->用户说明->文本=L“新名称:”;
// 
//btnAdd
// 
此->btnAdd->位置=系统::图纸::点(104149);
此->btnAdd->名称=L“btnAdd”;
此->btnAdd->尺寸=系统::图纸::尺寸(75,23);
此->btnAdd->TabIndex=4;
此->btnAdd->文本=L“添加!”;
此->btnAdd->UseVisualStyleBackColor=true;
this->btnAdd->Click+=gcnewsystem::EventHandler(this,&AddName::btnAdd_Click);
// 
//地址名
// 
这->自动缩放尺寸=系统::图纸::尺寸(6,13);
这->AutoScaleMode=System::Windows::Forms::AutoScaleMode::Font;
这->ClientSize=System::Drawing::Size(284262);
此->控制->添加(此->btnAdd);
此->控制->添加(此->用户指令);
此->控件->添加(此->名称输入);
此->控制->添加(此->复选框);
此->控制->添加(此->复选框);
此->名称=L“AddName”;
此->文本=L“AddName”;
此->恢复布局(错误);
此->执行布局();
}
#布拉格端区
私有:系统::Void btnAdd_单击(系统::对象^sender,系统::事件参数^e)
{
布尔警告=假;
int duptimes1=0;
int duptimes2=0;
字符串^Name=NameInput->Text;
字符串名称=封送(名称);
发电机组名称(“FirstNames.txt”、“LastNames.txt”);
if(字符串::IsNullOrEmpty(名称输入->文本))
{
MessageBox::Show(“请输入要输入的名称!”);
}
如果(!FNCheckBox->
String^ message = "That name is already in First Names " + duptimes1 + " times and Last Names " + duptimes2 " . Would you like to add it anyways?";
String^ message = "That name is already in First Names " + duptimes1 + " times and Last Names " + duptimes2 + " . Would you like to add it anyways?";