用c++代码获取svn的版本号

#include 
#include 
#include 

std::string exec(const char* cmd) {
    char buffer[128];
    std::string result = "";
    FILE* pipe = _popen(cmd, "r");
    if (!pipe) {
        throw std::runtime_error("popen() failed!");
    }
    while (!feof(pipe)) {
        if (fgets(buffer, 128, pipe) != nullptr) {
            result += buffer;
        }
    }
    _pclose(pipe);
    return result;
}

std::string getSvnRevision() {
    std::string cmd = "svn info --show-item revision";
    std::string result = exec(cmd.c_str());
    // 移除末尾的换行符
    result.erase(result.find_last_not_of("\r\n") + 1);
    return result;
}

int main() {
    std::string svnRevision = getSvnRevision();
    std::cout << "SVN 版本号: " << svnRevision << std::endl;
    system("pause");
    return 0;
}

你可能感兴趣的:(C++,c++,svn,开发语言)