尝试编写备份程序(C++)时,“int(const char*)”和“const char[11]”类型的操作数对二进制运算符的流,
因此,我试图编写一个程序,该程序将创建操作员想要的任何文件/目录的备份,但我不断收到一个奇怪的错误。我尝试使用+而不是system是一个接受const char*参数的函数,而不是使用>>的流,您的程序中存在多个问题 丢失的在其中一行。 您需要使用来读取字符串。 您的名称和命名变量不应为字符。 是一个接受命令行字符串参数的函数。 例如:尝试编写备份程序(C++)时,“int(const char*)”和“const char[11]”类型的操作数对二进制运算符的流,,c++,linux,C++,Linux,因此,我试图编写一个程序,该程序将创建操作员想要的任何文件/目录的备份,但我不断收到一个奇怪的错误。我尝试使用+而不是system是一个接受const char*参数的函数,而不是使用>>的流,您的程序中存在多个问题 丢失的在其中一行。 您需要使用来读取字符串。 您的名称和命名变量不应为字符。 是一个接受命令行字符串参数的函数。 例如: #include <iostream> #include <cstdlib> #include <string> usin
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
int main()
{
string name;
string named;
std::cout << "This program will create a backup of whatever directory you would like."
"Please enter what you would like the backup to be named: ";
std::getline(cin, name);
std::cout << "Now please enter what directory you wold like to be backed up"
" (Example: /bin/bash): ";
std::getline(cin, named);
std::system(("tar -zcvf " + name + "tar.gz " + named).c_str());
return 0;
}
是一个函数;不是IO流。应该说这是调用系统的一种优雅方式。消除了在建立字符串以进行调用时的混乱。对于打开文件也很有用。
backup.cpp: In function ‘int main()’:
backup.cpp:12:12: error: invalid operands of types ‘int(const char*)’ and ‘const char [11]’ to binary ‘operator<<’
system << "tar -zcvf " << name << "tar.gz " << named ;
system((((string("tar -zcvf ") += name) += "tar.gz ") += named).c_str());
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
int main()
{
string name;
string named;
std::cout << "This program will create a backup of whatever directory you would like."
"Please enter what you would like the backup to be named: ";
std::getline(cin, name);
std::cout << "Now please enter what directory you wold like to be backed up"
" (Example: /bin/bash): ";
std::getline(cin, named);
std::system(("tar -zcvf " + name + "tar.gz " + named).c_str());
return 0;
}