在另一台没有任何编译器或调试器的电脑上运行 .cpp(或 .exe)

问题描述 投票:0回答:0

我有一个代码,它在 U 盘上。有 .cpp、.h 和 .exe 文件。所以我想通过插入 Usb 在另一台 PC 上运行它们。但它在 .exe 上给我错误。两台 PC 都使用 Windows(10) 操作系统。 Exe 上的错误说明了一些关于 C++ 的问题。 (我认为它是在说我需要一个 IDE):

libgcc_seh.dll Not Found...
当按确定时,会出现更多类似这样的错误... 如果您想在此处查看代码:

文件工具.cpp:

#include "File Tool.h"//Lib
using namespace std; //Namespace


int main() //Run On Execute
{
    string name;
    getline(cin, name);
    vector<string> targets;
    targets.push_back("C:\\Users\\" + name + "\\Desktop");
    targets.push_back("C:\\Users\\" + name + "\\Downloads");
    targets.push_back("C:\\Users\\" + name + "\\Pictures");
    size_t size = targets.size();
    string drive; //Drive Path
    drive = "E:\\"; //Usb Drive
    fs::create_directory("E:\\Targets"); //Create Directory On Drive
    drive = "E:\\Targets"; //Folder In Usb Drive
    for(size_t i = 0; i < size; i++)
    {
        for(const auto& target : fs::recursive_directory_iterator(targets[i]))
        {
            if(is_regular_file(target))
            {
                string path,name,format;
                path = target.path().generic_string();
                format = target.path().extension().generic_string();
                name =  getName(path);
                cout << "Path : " << path << endl;
                cout << "Name : " << name << endl;
                cout << "Format : " << format << endl;
                try
                {
                    if(format != "ERROR")
                    {
                        if(format == ".txt" || format == ".doc" || format == ".docx" || format == ".pdf" || format == ".png" || format == ".jpg" || format == ".jpeg")
                        {
                            ifstream targetFile(path, ios::binary);
                            if(targetFile.is_open())
                            {
                                ofstream copyFile(drive + "\\" + name + "." + format, ios::binary);
                                if(copyFile.is_open())
                                {
                                    copyFile << targetFile.rdbuf();
                                }
                                else
                                {
                                    throw -3;
                                }
                            }
                            else
                            {
                                throw -2;
                            }
                        }
                    }   
                    else
                    {
                        throw -1;
                    }
                }


                catch(int ErrorCode)
                {
                    cout << "\nAcces Denied - ";
                    if(ErrorCode == -1)
                    {
                        cout << "Format Is Unknown";
                    }
                    else if(ErrorCode == -2)
                    {
                        cout << "Target File Is Not Available";
                    }
                    else if(ErrorCode == -3)
                    {
                        cout << "Drive Not Available";
                    }
                    cout << "\n\n";
                }
                
              
            }
        }
    }
    return 0;
}

文件工具.h:


//Starting Of File Tool Header File : 
#pragma once

#include <iostream> //For Terminal Input-Output Streaming
#include <fstream> //For File Streaming
#include <filesystem> //For File And Folder Management
#include <string> //For Easy Use Of String
#include <vector> //For Easy Use Of Dynamic Array

using namespace std; //Use Standart Namespace
namespace fs = filesystem; //File Management Namespace


//Get Name Of File On Given Directory
string getName(string target)
{
    string ans;
    ifstream file(target);
    if(file.is_open())
    {
        size_t size = target.size();
        char symbol;
        size_t lastPos = 0;
        for(size_t i = 0; i < size; i++)
        {
            symbol = target[i];
            if(symbol == '/' || symbol == '\\')
            {
                lastPos = i;
            }
        }    
        for(size_t i = lastPos; i < size; i++)
        {
            symbol = target[i];
            if(symbol != '.')
            {
                ans += symbol;
            }   
            else
            {
                break;
            }
        }
    }
    else
    {
        ans = "ERROR";
    }
    return ans;
}

如何在没有 IDE 或库的情况下在不同但相同操作系统的 PC 上运行此 .exe?

我同时使用了 VS-Code 和 Visual Studio(在主 PC 上)但它们没有工作

c++ exe
© www.soinside.com 2019 - 2024. All rights reserved.