обнаружен многократно определённый символ - один или более. хотя функция вынесена в загол файл

//файл Header.h:

#pragma once
#include <string>
std::string& Convert_String_to_string(System::String^ s, std::string& os);

std::string& Convert_String_to_string(System::String^ s, std::string& os) {
    using namespace System::Runtime::InteropServices;
    const char* chars =
        (const char*)(Marshal::StringToHGlobalAnsi(s)).ToPointer();
    os = chars;
    Marshal::FreeHGlobal(System::IntPtr((void*)chars));
    return os;
}

//DelForm.cpp:

#pragma once
#include "MyForm1.h"
#include "DelForm.h"
#include "Header.h"
System::Void PRAXISPRAXIS::DelForm::button1_Click(System::Object^ sender, System::EventArgs^ e)
{
    MyForm1^ main = dynamic_cast<MyForm1^>(Owner);
    String^ filename = main->textBoxAdmin->Text->ToString();
    std::string fname;
    Convert_String_to_string(filename, fname);

    if (std::remove(fname.c_str()) != 0) { MessageBox::Show("Неудаётся удалить!", "Ошибка!"); }
    else { MessageBox::Show("Файл успешно удалён!", "Ошибка!"); }
    this->Hide();
}

//AddForm.cpp

#pragma once
#include <fstream>
#include <iostream>
#include "AddForm.h"
#include "MyForm1.h"
#include <iomanip>
#include "Header.h"


System::Void PRAXISPRAXIS::AddForm::button2_Click(System::Object^ sender, System::EventArgs^ e)
{
    MyForm1^ form = gcnew MyForm1();
    this->Hide();
    form->Show();
}

System::Void PRAXISPRAXIS::AddForm::button1_Click(System::Object^ sender, System::EventArgs^ e)
{
    Application::Exit();
}


//сохранить
System::Void PRAXISPRAXIS::AddForm::button3_Click(System::Object^ sender, System::EventArgs^ e)
{
    static bool count = false, count1=false;
    int check = 0, checkColor = 0;
    String^ text1 = textBox_street->Text->ToString();
    std::string text;
    Convert_String_to_string(text1, text);

    if (!((text[0] >= 'A' && text[0] <= 'Z') || (text[0] >= 'А' && text[0] <= 'Я') || text[0] == 'Ё' || (text[0] >= '0' && text[0] <= '9'))) {
        check = 1; //ошибка
    }
    if (text.length() > 20) {
        check = 1;
    }
    if (text.length() > 1) {
        for (int i = 1; i < text.length(); i++) {
            if (text[i] == ' ' || (text[i] >= '0' && text[i] <= '9') || text[i] == '-' || (text[i] >= 'a' && text[i] <= 'z') || (text[i] >= 'а' && text[i] <= 'я') || text[i] == 'ё') {
                continue;
            }
            else {
                check = 1;
                break;
            }
        }
    }
    if (check != 0) {
        this->textBox_street->BackColor = System::Drawing::Color::Red; checkColor = 1;
    }
    
    int hn, fn, an, la, ta;
    hn = Convert::ToInt32(numericUpDown_house_number->Value);
    fn = Convert::ToInt32(numericUpDown_floor_number->Value);
    an = Convert::ToInt32(numericUpDown_apartment_number->Value);
    la = Convert::ToDouble(numericUpDown_living_area->Value);
    ta = Convert::ToDouble(numericUpDown_total_area->Value);

    if (hn  == 0) {
        this->numericUpDown_house_number->BackColor = System::Drawing::Color::Red; checkColor = 1;
    }

    if (fn == 0) {
        this->numericUpDown_floor_number->BackColor = System::Drawing::Color::Red; checkColor = 1;
    }

    if (an == 0) {
        this->numericUpDown_apartment_number->BackColor = System::Drawing::Color::Red; checkColor = 1;
    }

    if (la == 0) {
        this->numericUpDown_living_area->BackColor = System::Drawing::Color::Red; checkColor = 1;
    }

    if (ta == 0) {
        this->numericUpDown_total_area->BackColor = System::Drawing::Color::Red; checkColor = 1;
    }

    int y = Convert::ToDouble(numericUpDown_year_of_commissioning->Value);

    String^ filename = textBox1->Text->ToString();
    std::string fname;
    Convert_String_to_string(filename, fname);
    if (!count) {
        std::ifstream file(fname.c_str()); // попытка открыть файл
        if (file) {
            // файл существует
            MessageBox::Show("Файл с таким именем уже существует!", "Ошибка!");
            file.close(); 
            checkColor = 1;
            this->textBox1->BackColor = System::Drawing::Color::Red;
            
        }

        String^ forbidden = " ~#%&*{}:<>?/+|";
        if (!(filename->EndsWith(".txt") && (filename->CompareTo("-.txt")) && (filename->IndexOfAny(forbidden->ToCharArray()) == -1))) {
            this->textBox1->BackColor = System::Drawing::Color::Red;
            checkColor = 1;
            MessageBox::Show("Недопустимое название файла!", "Ошибка!");
        }
        count1 = true;
    }

    if (checkColor == 0) {
        

        std::ofstream outputFile;
    
            outputFile.open(fname.c_str(), std::ios::out | std::ios::app);

            if (!outputFile.is_open()) {
                MessageBox::Show("Неудаётся открыть файл для записи!", "Ошибка!");
                return;
            }
            
        outputFile << std::left << std::setw(20) << std::setfill(' ') << text;
        outputFile << std::right << std::setw(9) << std::setfill(' ') << hn;
        outputFile << std::right << std::setw(5) << std::setfill(' ') << y;
        outputFile << std::right << std::setw(14) << std::setfill(' ') << fn;
        outputFile << std::right << std::setw(15) << std::setfill(' ') << an;
        outputFile << std::right << std::setw(12) << std::setprecision(2) << std::fixed << la;
        outputFile << std::right << std::setw(12) << std::setprecision(2) << std::fixed << ta << std::endl;

        outputFile.close();


        if (!count) {
            textBox1->ReadOnly = true;
            label6->Text = "ПРОДОЛЖЕНИЕ ВВОДА ДАННЫХ В ФАЙЛ";
            button3->Text = "СОХРАНИТЬ ДАННЫЕ";
            count = true;
        }
        

        textBox_street->Text = "";
        numericUpDown_house_number->Value = 0;
        numericUpDown_floor_number->Value= 0;
        numericUpDown_apartment_number->Value = 0;
        numericUpDown_living_area->Value = 0;
        numericUpDown_total_area->Value = 0;
        numericUpDown_year_of_commissioning->Value = 2023;

        numericUpDown_house_number->BackColor = System::Drawing::Color::White;
        textBox_street->BackColor = System::Drawing::Color::White;
        numericUpDown_floor_number->BackColor = System::Drawing::Color::White;
        numericUpDown_apartment_number->BackColor = System::Drawing::Color::White;
        numericUpDown_living_area->BackColor = System::Drawing::Color::White;
        numericUpDown_total_area->BackColor = System::Drawing::Color::White;
        numericUpDown_year_of_commissioning->BackColor = System::Drawing::Color::White;
    }
}





Ответы (0 шт):