鱼C论坛

 找回密码
 立即注册
查看: 2232|回复: 1

[已解决]c++字符串函数的使用

[复制链接]
发表于 2018-2-12 11:24:08 | 显示全部楼层 |阅读模式
5鱼币
  1. #include <iostream>
  2. #include <string>

  3. int main()
  4. {
  5.     std::cout<<"请输入一串字符串:";
  6.     std::string str;
  7.     std::string str1;

  8.     std::getline(std::cin,str);
  9.     str1.copy(str,10,0);

  10.     std::cout<<"您输入的字符串为:"<<str<<std::endl;
  11.     std::cout<<"拷贝后的字符串为:"<<str1<<std::endl;


  12.     return 0;
  13. }
复制代码

使用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函数到底怎么用的,求大佬解。
最佳答案
2018-2-12 11:24:09
如需拷贝到另一个string对象中请使用 = 号重载运算符

  1. #include <iostream>
  2. #include <string>

  3. int main()
  4. {
  5.         std::cout << "请输入一串字符串:";
  6.         std::string str;
  7.         std::string str1;

  8.         std::getline(std::cin, str);
  9.         str1 = str;

  10.         std::cout << "您输入的字符串为:" << str << std::endl;
  11.         std::cout << "拷贝后的字符串为:" << str1 << std::endl;

  12.         return 0;
  13. }
复制代码

最佳答案

查看完整内容

如需拷贝到另一个string对象中请使用 = 号重载运算符
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-2-12 11:24:09 | 显示全部楼层    本楼为最佳答案   
如需拷贝到另一个string对象中请使用 = 号重载运算符

  1. #include <iostream>
  2. #include <string>

  3. int main()
  4. {
  5.         std::cout << "请输入一串字符串:";
  6.         std::string str;
  7.         std::string str1;

  8.         std::getline(std::cin, str);
  9.         str1 = str;

  10.         std::cout << "您输入的字符串为:" << str << std::endl;
  11.         std::cout << "拷贝后的字符串为:" << str1 << std::endl;

  12.         return 0;
  13. }
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-3-29 22:47

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表