STL string赋值的困惑

ydfok 2003-08-14 04:49:49
我定义了一个
struct yyy
{
string name;
string PWD;
};

yyy test;

以后赋值的时候,我就 test.name.assign(str,str.begin(),str.end());
可是不对
不知道是什么原因
难道是struct里面不可以直接用string吗?
盼高手帮忙指点~~
...全文
60 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
yjh1982 2003-08-14
  • 打赏
  • 举报
回复
同意jyfcsdn,或:
test.name.assign(str)即可
jyfcsdn 2003-08-14
  • 打赏
  • 举报
回复
assign(str,str.begin(),str.end());有这样用的码

assign(str.begin(),str.end());
fangrk 2003-08-14
  • 打赏
  • 举报
回复
basic_string& assign(const basic_string&)
basic_string& assign(const basic_string& s,
size_type pos, size_type n)
basic_string& assign(const charT* s, size_type n)
basic_string& assign(const charT* s)
basic_string& assign(size_type n, charT c)
template <class InputIterator>
basic_string& assign(InputIterator first, InputIterator last)


#include <iostream>
#include <string>
using namespace std;

int main()
{
string str1="I don't wanna see,see us apart",str2;
cout<<str1<<"\t"<<str2<<endl;
str2.assign(str1.begin(),str1.end());
cout<<str1<<"\t"<<str2<<endl;
}

69,372

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧