使用cin从c++中命名tarball文件

use cin to name a tarball from with C++

本文关键字:tarball 文件 cin c++ 使用      更新时间:2023-10-16

这是我目前的代码,我难住了。是的,我对c++有点陌生

#include <iostream>
#include <string>
int main()
{
    using std::string;
    using std::cin;
    using std::cout;
    string projectname;
    std::cout << "Enter your project folders name: ";
    std::cin >> projectname;
    // Idea is to call tar, gzip and zip
    // Create the tarball from using cin for file title
    system("tar -cvf projectname.tar");  projectname;
    // using cin gzip the tarball
    system("gzip projectname.tar");
    // then call md5sum and sha1sum to get the hash for each
    system("md5sum projectname.tar.gz > gz.log");
    system("pause");
    return 0;
}

这不起作用,我需要它从cin

获取文件变量

您需要添加命令的单独部分,在相关位置插入变量projectname,如下所示:

#include <iostream>
#include <string>
int main()
{
    using std::string;
    using std::cin;
    using std::cout;
    string projectname;
    std::cout << "Enter your project folders name: ";
    std::cin >> projectname;
    // Idea is to call tar, gzip and zip
    // add the different parts into a string
    // then convert to a char const* using c_str()
    system(("tar -cvf '" + projectname + ".tar' '" + projectname + "'").c_str());
    // Same thing broken down
    string command = "gzip '";
    command += projectname;
    command += ".tar'";
    system(command.c_str());
    // etc....
}