请问为什么字符串不能直接赋值,编译过了,运行是错的
#include <iostream>
using namespace std;
void swap(struct List &a,struct List &b);
#include <string>
#include<cstring>
// 00100 6 4
//00100 1 12309 00000 4 33218
//12309 2 33218 33218 3 12309
//33218 3 00000 12309 2 00100
//00000 4 99999 00100 1 99999
//99999 5 68237 99999 5 68237
//68237 6 -1 68237 6 -1
struct List{
string add;
int value;
string next;
};
int main()
{
string headadd;
int n,node;
cin>>headadd>>n>>node;
List a[n];
for(int i=0;i<n;i++)
{
cin>>a[i].add>>a[i].value>>a[i].next;
}
for(int j=1;j<n;j++)
{
for(int k=j;k<n;k++)
{
if(a[k].add == headadd)
{
swap(a[k],a[0]);
}
}
}
for(int j=0;j<n;j++)
{
for(int k=j+1;k<n;k++)
{
if(a[k].add == a[j].next)
{
swap(a[k],a[j+1]);
}
}
}
for(int i=0;i<n;i++)
{
cout<<a[i].value<<endl;
}
cout<<"here:"<<endl;
//node=4,n=6
for(int cnt=0;cnt<n/node;)//控制有几次循环
{
for(int jud=cnt;jud<node/2;jud++)//控制每次循环的开始位置以及循环次数
{
swap(a[jud],a[node-jud-1]);
}
cnt += node;
}
for(int i=0;i<n;i++)//遍历链表并将链表的下一个地址改变
{
a[i].next = a[i+1].add;
}
a[n-1].next = '-1';
for(int i=0;i<n;i++)
{
cout<<a[i].add<<" "<<a[i].value<<" "<<a[i].next<<endl;
}
}
void swap(struct List &a,struct List &b)
{
struct List L;
L.add = a.add;
L.value = a.value;
L.next = a.next;
a.add = b.add;
a.value = b.value;
a.next =b.next;
b.add = L.add;
b.value = L.value;
b.next = L.next;
}