2014-04-26 79 views
0

因此,互聯網說這個錯誤意味着我錯過了一個;某處,但據我所知,我沒有這個錯誤。該代碼應該詢問用戶是否要添加單詞,即使它已經在列表中,然後相應地響應輸入。我平均使用C++,但是新增了GUI,所以我不熟悉所有系統關鍵字。我正在使用Visual Studio 2010.我將爲您提供包含錯誤和頭文件的代碼。 這是我AddName.h,157線,我初始化消息有錯誤C2143C2143系統字符串錯誤

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

讓我知道如果你需要了解更多信息或在那裏我可以去找出問題的所在!

+3

where is _line 157_? – timrau

+3

錯誤的語言標記。 – juanchopanza

+0

哪一條是157行?在代碼中標註註釋。 –

回答

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

+1,趕上! – herohuyongtao

+0

這樣做!非常感謝!對於花費我幾個小時的問題,這似乎是一個明顯的解決方案。非常感謝! – Kerbz713