c++字符串函数的使用
#include <iostream>#include <string>
int main()
{
std::cout<<"请输入一串字符串:";
std::string str;
std::string str1;
std::getline(std::cin,str);
str1.copy(str,10,0);
std::cout<<"您输入的字符串为:"<<str<<std::endl;
std::cout<<"拷贝后的字符串为:"<<str1<<std::endl;
return 0;
}
使用copy函数时报错:H:\c++\class_seven001\main.cpp|11|error: no matching function for call to 'std::__cxx11::basic_string<char>::copy(std::__cxx11::string&, int, int)'|
copy函数到底怎么用的,求大佬解。 如需拷贝到另一个string对象中请使用 = 号重载运算符
#include <iostream>
#include <string>
int main()
{
std::cout << "请输入一串字符串:";
std::string str;
std::string str1;
std::getline(std::cin, str);
str1 = str;
std::cout << "您输入的字符串为:" << str << std::endl;
std::cout << "拷贝后的字符串为:" << str1 << std::endl;
return 0;
}
页:
[1]