C2143系统字符串错误

时间:2014-04-26 17:26:06

标签: string c++-cli

所以互联网说这个错误意味着我错过了一个;在某个地方,但据我所知,我没有那个错误。该代码应该询问用户是否想要添加单词,即使它已经在列表中,然后相应地响应输入。我对c ++很平均,但对GUI很新,所以我不熟悉所有系统关键词。我正在使用Visual Studio 2010.我将为您提供包含错误和头文件的代码。 这是我的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;
    };

如果您需要更多信息或我可以在哪里找出问题所在,请告诉我们!

1 个答案:

答案 0 :(得分:4)

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?";