测试插入代码
测试1:直接复制粘贴文本的方式
#include<iostream>
#include<string>
int main()
{
std::cout << "please enter your first name:";
std::string name;
std::cin >> name;
const std :: string greeting = "hello,"+ name + "!";
const std :: string spaces(greeting.size(),' ');
const std :: string second ="*" + spaces + "*";
const std :: string first (second.size(),'*');
std :: cout <<std ::endl;
std :: cout <<std::endl;
std :: cout <<first<<std::endl;
std :: cout <<second<<std::endl;
std :: cout <<"*"<<greeting<<"*"<<std ::endl;
std :: cout <<second<<std :: endl;
std :: cout <<first<<std::endl;
return 0;
}
测试2:插入代码的方式,注意选择编程语言
#include<iostream> #include<string> int main() { std::cout << "please enter your first name:"; std::string name; std::cin >> name; const std :: string greeting = "hello,"+ name + "!"; const std :: string spaces(greeting.size(),' '); const std :: string second ="*" + spaces + "*"; const std :: string first (second.size(),'*'); std :: cout <<std ::endl; std :: cout <<std::endl; std :: cout <<first<<std::endl; std :: cout <<second<<std::endl; std :: cout <<"*"<<greeting<<"*"<<std ::endl; std :: cout <<second<<std :: endl; std :: cout <<first<<std::endl; return 0; }
测试3:引用代码片的方式
#include #include int main() { std::cout << "please enter your first name:"; std::string name; std::cin >> name; const std :: string greeting = "hello,"+ name + "!"; const std :: string spaces(greeting.size(),' '); const std :: string second ="*" + spaces + "*"; const std :: string first (second.size(),'*'); std :: cout <<std ::endl; std :: cout <<std::endl; std :: cout <<first<<std::endl; std :: cout <<second<<std::endl; std :: cout <<"*"<<greeting<<"*"<<std ::endl; std :: cout <<second<<std :: endl; std :: cout <<first<<std::endl; return 0; }
分别使用三种方式插入代码片,具体何种方式最有效,得看博客审核通过后的实际情况了……