#include <iostream> #include <string> #include <fstream> int main(){ std::cout<<"Enter a line of text to back up: "; std::string line; std::getline(std::cin,line); std::string path; std::cout<<"Enter a file to append the text to (must be inside the /srv/backups directory): "; std::getline(std::cin,path); if(!path.starts_with("/srv/backups/")){ std::cout<<"The file must be inside the /srv/backups directory!\n"; } else{ std::ofstream backup_file(path,std::ios_base::app); backup_file<<line<<'\n'; } return 0;
理解问题#include <iostream> #include <string> #include <fstream> int main(){ std::cout<<"Enter a line of text to back up: "; std::string line; std::getline(std::cin,line); std::string path; std::cout<<"Enter a file to append the text to (must be inside the /srv/backups directory): "; std::getline(std::cin,path); if(!path.starts_with("/srv/backups/")){ std::cout<<"The file must be inside the /srv/backups directory!\n"; } else{ std::ofstream backup_file(path,std::ios_base::app); backup_file<<line<<'\n'; } return 0;
已完成理解「#include <iostream> #include <string> #include <fstream> int main(){ std::cout<<"Enter a line of text to back up: "; std::string line; std::getline(std::cin,line); std::string path; std::cout<<"Enter a file to append the text to (must be inside the /srv/backups directory): "; std::getline(std::cin,path); if(!path.starts_with("/srv/backups/")){ std::cout<<"The file must be inside the /srv/backups directory!\n"; } else{ std::ofstream backup_file(path,std::ios_base::app); backup_file<<line<<'\n'; } return 0;」
展开阅读网页