+ -
当前位置:首页 → 问答吧 → stl中的,queue, 居然只能push进去一个字符串?啥原因?

stl中的,queue, 居然只能push进去一个字符串?啥原因?

时间:2010-08-31

来源:互联网

#include <iostream>
#include <list>
#include <queue>

using namespace std;
typedef char* array;

queue<array>que;

int main()
{
/*
queue<int>q;
for (int i = 0; i < 10; i++)
{
    q.push(i);
}
cout << "The first element is:"<<q.front() <<endl
    <<"and the last element is:" <<q.back() << endl;
*/

char ss[1024];
char *s=ss;
for (int i=0; i<5; i++)
{
  cout << "please scanf" <<endl;
  scanf("%s", s);
  que.push(s);
}

while (!que.empty())
{
cout << "printf the queue "<< que.front() <<endl;
que.pop();
}

}

作者: keneth2078   发布时间: 2010-08-31

你每次放进去的都是ss的地址,而不是内容

作者: hellioncu   发布时间: 2010-08-31

回复 hellioncu

如果改为que.push(*s); 编译又出错,请大侠帮忙。。。

作者: keneth2078   发布时间: 2010-08-31

相关阅读 更多

热门下载

更多