no matching function for call to ‘std::basic_string<char>::assign(std::string&, int)
使用string中的assign赋值函数报错,代码为:
text0.assign(line,i+);
其中text0与line都为string类型
最后发现assign函数的原型为
string &assign(const char *s,int n);
将代码改为以下即可
text0.assign(line.c_str(),i+);
附 assign函数
string &operator=(const string &s);//把字符串s赋给当前字符串
string &assign(const char *s);//用c类型字符串s赋值
string &assign(const char *s,int n);//用c字符串s开始的n个字符赋值
string &assign(const string &s);//把字符串s赋给当前字符串
string &assign(int n,char c);//用n个字符c赋值给当前字符串
string &assign(const string &s,int start,int n);//把字符串s中从start开始的n个字符赋给当前字符串
string &assign(const_iterator first,const_itertor last);//把first和last迭代器之间的部分赋给字符串
及 char*、char[]与string转换方式
1. string --> char *
char * = string.c_str;
2. char * --> string
//可以直接赋值。 string s;
char *p = "abcdef";
s = p;
不过,变为string后使用printf输出会出现问题,用cout没有问题。是因为“%s”要求后面的对象的首地址。但是string不是这样的一个类型。
3. string --> char[]
不可直接赋值,使用循环赋值
string pp = "dagah";
char p[];
int i;
for( i=;i<pp.length();i++)
p[i] = pp[i];
p[i] = '\0';
printf("%s\n",p);
cout<<p;
4. char[] --> string
可以直接赋值,但会出现2中的问题
参考: http://blog.csdn.net/cogbee/article/details/8931838
no matching function for call to ‘std::basic_string<char>::assign(std::string&, int)的更多相关文章
- VC++ : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::basic_string<wchar_t,struct std::char_traits<wchar_t>
最近学习Google Breakpad,将其用在了自己的项目中,编译的版本为VS2010,没有什么问题.但是为了和之前的程序兼容,需要使用VS2008版本的程序,于是又编译了VS2008版本的代码,但 ...
- iOS出现 Undefined symbols for architecture armv7 std::basic_string<char, std::char_traits<char>
Undefined symbols for architecture i386: “_OBJC_CLASS_$_XXX”, referenced from: objc-class-ref in XXX ...
- 使用log4cplus时遇到的链接错误:无法解析的外部符号 "public: static class log4cplus::Logger __cdecl log4cplus::Logger::getInstance(class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,
#include "stdafx.h" #include <log4cplus/logger.h> #include <log4cplus/loggingmacr ...
- no suitable ctr exists to convert from 'int' to 'std::basic_string<char,std::char_traits<char>,std::allocator<char> >
int xfun(int *a,int n) { int x = *a;//a的类型是int *,a+1跳动一个int的长度 ; pa < a + n; pa++)//指向同一个类型的指针比较大 ...
- error LNK2019: 无法解析的外部符号 "class std::basic_ostream<char,struct std::char_traits<char> >
1,VS2013: 错误 1 error LNK2019: 无法解析的外部符号 "class std::basic_ostream<char,struct std::char_trai ...
- [Link 2005]vs2015 LNK2005 "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl printR(class std::basic_ostream<char,struct std::char_traits<char> > &,class QueryResult const &)" (?
vs2015 LNK2005 "class std::basic_ostream<char,struct std::char_traits<char> > &am ...
- 【CString与string转换】不存在从 "LPWSTR" 转换到 "std::basic_string<char, std::char_traits<char>, std::allocator(转)
原文转自 http://blog.csdn.net/qq_23536063/article/details/52291332 [问题描述] CString cstr: sring str(cstr.G ...
- error C3867: “std::basic_string<char,std::char_traits<char>,std::allocator<char>>::c_str”: 函数调用缺少参数列表;请使用“&std::basic_string<char,std::char_traits<char>,std::allocator<char>>::c_str”创建指向成员的指针
这个问题找了很多没有找到满意的答案.仔细看了一下,是使用了c_str的问题. 我直接把使用string.c_str的地方使用char*代替即解决问题.
- 【ERROR】no matching function for call to 'std::basic_ifstream<char>::basic_ifstream
错误记录:QT中使用 no matching function for call to 'std::basic_ifstream<char>::basic_ifstream(QString ...
随机推荐
- 查看 共享内存 的命令 ipcrm、ipcs
ipcrm 命令 移除一个消息对象.或者共享内存段,或者一个信号集,同时会将与ipc对象相关链的数据也一起移除.当然,只有超级管理员,或者ipc对象的创建者才有这项权利啦 ipcrm用法 ipcrm ...
- windows下mysql密码忘了怎么办?【转】
前两天在windows的command命令行下,用mysqladmin导入过一些站上数据 结果悲催了,mysql.user的内容被改了,root上不了了,权限也变了. 结合了网络上的集中方法,终于成了 ...
- maven中json-lib库无法引入
今天在maven中引入json-lib库,intellij中的pom文件没有报错,但是在类中就是无法使用. pom依赖配置: <dependency> <groupId>net ...
- Oracle 一个中文汉字 占用几个字节,由Oracle中字符集编码决定
Oracle 一个中文汉字 占用几个字节,要根据Oracle中字符集编码决定 查看oracle server端字符集 select userenv('language') from dual; 如果显 ...
- linux mount 挂接新硬盘
1.先用fdisk -l查看一下,先加入的外设地址名称 2. #fdisk /dev/sdb进入fdisk模式:Command (m for help):p //查看新硬盘的分区Command ( ...
- 本地文件到通过flume到kafka
配置文件 cd /usr/app/flume1.6/conf vi flume-dirKakfa.properties #agent1 name agent1.sources=source1 agen ...
- 针对降质模型中的模糊SR
(PDF) Deep Plug-and-Play Super-Resolution for Arbitrary Blur Kernels https://www.researchgate.net/pu ...
- mysql数据库2
命令行客户端软件MySQL Command Line Client, 打开该程序,输入数据库密码,登陆到MySQL软件, 如果想通过该命令行工具来操作MySQL软件,只需要在"mysql&g ...
- mysql中如何查看某个日期所在的周一是几号?某个日期所在的一周开始时间是几号?
需求描述: 在编写SQL的时候,有这么个需求,就是要查出来某个日期所在的周一是几号,进行了测试,在此进行记录下. 测试过程: 议题:查看某个日期所在的周一是几号 分析:如果某个日期是周一,那么加上整数 ...
- MAC软件下载比较好的三个第三方网站
http://soft.macx.cn; http://www.applex.net: http://www.macdang.com;