C++中如何把list容器的元素复制到另一个list容器中

假如有两个容器list<string>a和list<string>b;我想把a的第二个至最后的元素复制到b中(即不要a的首元素),应如何做??... 假如有两个容器list<string> a和list<string> b;
我想把a的第二个至最后的元素复制到b中(即不要a的首元素),应如何做??
展开
 我来答
百度网友96ffcf7
推荐于2016-05-12 · 知道合伙人互联网行家
百度网友96ffcf7
知道合伙人互联网行家
采纳数:22721 获赞数:118724
从事多年网络方面工作,有丰富的互联网经验。

向TA提问 私信TA
展开全部
使用很简单:启动后将鼠标移到别的软件的LISTBOX,按F5,软件LISTBOX的内容就被复制到它的LISTBOX中了。
‘Module1------------------------------
Option Explicit
Type POINTAPI
x As Long
y As Long
End Type
Public Const LB_GETTEXT = &H189
Public Const LB_GETCOUNT = &H18B
Public Declare Function SendMessageBynum& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long)
Public Declare Function SendMessageByString& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String)
Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long

Public Function EnumWindows_CBK(ByVal hwnd As Long, ByVal lParam As Long) As Long
Form1.List1.AddItem Str(hwnd)
EnumWindows_CBK = 1
End Function

’Form1--------------------------------

Option Explicit
Dim win As Long
Dim wintxt As String
Dim i As Integer
Dim MyStr As String
Dim xy As POINTAPI
Dim kq As Boolean
Dim txt As String

Private Sub Form_Load()
kq = False
End Sub

Private Sub List1_Click()
If List1.ListIndex >= 0 Then Text4 = List1.List(List1.ListIndex)
End Sub

Private Sub List2_Click()
If List2.ListIndex >= 0 Then Text5 = List2.List(List2.ListIndex)
End Sub

Private Sub Timer1_Timer()
Dim i As Long
Dim TListCount As Long
Dim TListTexts As String
GetCursorPos xy
win = WindowFromPoint(xy.x, xy.y)
MyStr = String(100, Chr$(0))
List1.Clear
EnumChildWindows win, AddressOf EnumWindows_CBK, 1
Text1.Text = List1.ListCount
For i = 0 To List1.ListCount - 1
GetWindowText Val(List1.List(i)), MyStr, 100
List1.List(i) = List1.List(i) & " " & MyStr
Next
txt = String(100, Chr$(0))
GetWindowText win, txt, 100
Text2.Text = Str(win) & " " & txt

TListCount = SendMessageBynum&(win, LB_GETCOUNT, 0&, 0&)'得到项目数
Text3 = TListCount
List2.Clear
For i = 0 To TListCount - 1'将内容添加到列表框
TListTexts = String$(255, 0)
SendMessageByString& win, LB_GETTEXT, i, TListTexts
TListTexts = Left$(TListTexts, InStr(1, TListTexts, Chr$(0)) - 1)
List2.AddItem TListTexts
Next i
End Sub
Private Function MyHotKey(vKeyCode) As Boolean
MyHotKey = (GetAsyncKeyState(vKeyCode) < 0)
End Function

Private Sub Timer2_Timer()

If MyHotKey(vbKeyF5) Then
If kq = False Then
Timer1.Enabled = True
kq = True
Else
Timer1.Enabled = False
kq = False
End If
End If
End Sub
fly_fire
推荐于2016-02-29 · TA获得超过617个赞
知道小有建树答主
回答量:579
采纳率:0%
帮助的人:305万
展开全部
把迭代器从第二个开始拷贝就可以了,也可以用通用算法,我这里就直接拷贝了。
#include <iostream>
#include <list>
using namespace std;

int main()
{
list<int> a;
list<int> b;
int i;
for (i=0; i < 30; ++i, a.push_back(i));
std::list<int>::iterator rit = a.begin();
std::list<int>::iterator rend = a.end();
for(++rit;rit != rend;++rit)
b.push_back(*rit);

rit=b.begin();
rend=b.end();
for(;rit != rend;++rit)
cout << *rit << ", ";
return 0;
}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
kong_yuyu
2008-04-27 · 超过14用户采纳过TA的回答
知道答主
回答量:40
采纳率:0%
帮助的人:36万
展开全部
在list里面建立一个method用来copy
void List::CopyFrom(const List otherList)
{
for(int a=1;a++;a<length) //这个长度是a的。。
{
.....//其中过程取决于你用的是普通array list
//还是linked list
//反正一项一项对应的copy就可以了
}
}
使用的时候 b.CopyFrom(a); 就可以了!

或者如果你有method能在main()里面读取到a的内容,也可以就在main()里面用loop边读取a的每一个项,边用Insert这个method放到b里面去!

希望能解答你的问题!
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
帐号已注销
2008-05-09 · 超过16用户采纳过TA的回答
知道答主
回答量:157
采纳率:0%
帮助的人:64.6万
展开全部
用迭代器.. 跟数组的指针一个用法
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
universesingle
2008-04-27 · TA获得超过492个赞
知道小有建树答主
回答量:965
采纳率:0%
帮助的人:417万
展开全部
弄俩数组
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 2条折叠回答
收起 更多回答(3)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式