Frage

So the internet says that this error means that I'm missing a ; somewhere, but as far as I can tell, I don't have that error. This code is supposed to ask the user if they want to add the word even if it's in the list already and then respond to the input accordingly. I'm average with c++ but new to GUI so I'm not familiar with all the system key words. I'm using Visual Studio 2010. And I'll give you the code with the errors and the header files included. This is my AddName.h, Line 157 where I initialize message has the error 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;
    };

Let me know if you need more information or where I can go to figure out where the problem is!

War es hilfreich?

Lösung

String^ message = "That name is already in First Names " + duptimes1 + " times and Last Names " + duptimes2 " . Would you like to add it anyways?";

You missed a "+" at the end there.

String^ message = "That name is already in First Names " + duptimes1 + " times and Last Names " + duptimes2 + " . Would you like to add it anyways?";
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top