请问在VC中要用到deque,该怎么用啊?在线等待,我管撒分啊:)

yj_nj 2004-03-19 01:17:18
我是这样用的,老是报错!

#include <deque.h>

{
deque<long>;
//或deque<char *>;
}

请大侠指点!!!
...全文
170 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
ACuke 2004-09-17
  • 打赏
  • 举报
回复
给你一个例子 我刚调试通过

#ifndef MTDEQUE_H
#define MTDEQUE_H

#include <deque>
using namespace std;

class MTdeque
{
protected:
const m_iMaxSize;
deque <char> m_Queue;
CRITICAL_SECTION m_Lock;
public:
//Construction
MTdeque( int max_size ) : m_iMaxSize( max_size )
{
::InitializeCriticalSection(&m_Lock);
}
//Destruction
~MTdeque()
{
::DeleteCriticalSection(&m_Lock);
}
// Return deque's FreeSpace
int SpaceFree()
{
::EnterCriticalSection(&m_Lock);
int size = m_iMaxSize - m_Queue.size();
::LeaveCriticalSection(&m_Lock);
return (size < 0) ? 0 : size;
}
// Return deque's UsedSpace
int SpaceUsed()
{
::EnterCriticalSection(&m_Lock);
int size = m_Queue.size();
::LeaveCriticalSection(&m_Lock);
return size;
}
// Insert a char to deque
int Insert(char c)
{
int return_value = -1;
::EnterCriticalSection(&m_Lock);
if (m_Queue.size() < m_iMaxSize)
{
m_Queue.push_back(c);
return_value = c&0xff;
}
::LeaveCriticalSection(&m_Lock);
return return_value;
}
// Insert count chars to deque
int Insert(char *data, int count)
{
::EnterCriticalSection(&m_Lock);
int actual = m_iMaxSize - m_Queue.size();

if ( actual < 0 )
{
actual = 0;
}

if ( count < actual )
{
actual = count;
}

for (int i=0; i<actual; i++)
{
m_Queue.push_back( *data++ );
}
::LeaveCriticalSection(&m_Lock);
return actual;
}
// get max char and put these to *data from deque
// and clear these char
int Extract(char *data, int max)
{
int i = 0;
::EnterCriticalSection(&m_Lock);
while ( i<max && m_Queue.size() )
{
data[i++] = m_Queue.front();
m_Queue.pop_front();
}
::LeaveCriticalSection(&m_Lock);
return i;
}
// get max char and put these to *data from deque
// and do not clear these char
int Peek(char *data, int max)
{
::EnterCriticalSection(&m_Lock);
if ( max > m_Queue.size() )
{
max = m_Queue.size();
}
for (int i=0; i<max; i++)
{
data[i] = m_Queue.begin()[i];
}
::LeaveCriticalSection(&m_Lock);
return i;
}
// get a char from deque
// and clear this char
int Extract()
{
int return_value = -1;
::EnterCriticalSection(&m_Lock);
if ( m_Queue.size() )
{
return_value = m_Queue.front() & 0xff;
m_Queue.pop_front();
}
::LeaveCriticalSection(&m_Lock);
return return_value;
}
// clear all data from deque
void Clear()
{
::EnterCriticalSection(&m_Lock);
m_Queue.clear();
::LeaveCriticalSection(&m_Lock);
}
};

#endif
wcw168 2004-09-17
  • 打赏
  • 举报
回复
// deque.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <deque>
#include <iostream>
using namespace std;

int main(int argc, char* argv[])
{
deque<int> tst;
deque<int>::iterator it;

for (int i=0; i<10; i++)
tst.push_back(i);
for (it=tst.begin(); it!=tst.end(); it++)
cout << *it << endl;

return 0;
}

这个程序我测试过了,可以实现deque的读写操作。
yj_nj 2004-03-19
  • 打赏
  • 举报
回复
// 这是使用应用程序向导生成的 VC++
// 应用程序项目的主项目文件。

#include "stdafx.h"
#include <deque>
#using <mscorlib.dll>
#include <tchar.h>

using namespace System;

// 这是此应用程序的入口点
int _tmain(void)
{
// TODO: 请用您自己的代码替换下面的示例代码。
deque<int> a;
Console::WriteLine(S"Hello World");
return 0;
}

故障依旧!
yj_nj 2004-03-19
  • 打赏
  • 举报
回复
忘了说了,我是用的.NET,新建一个C++托管项目也不行,是不是有哪里要设啊?!
yj_nj 2004-03-19
  • 打赏
  • 举报
回复
#ifndef FILEMGMT_H_
#define FILEMGMT_H_

#include <deque>
//using namespace std;

deque <int> c1;

class CFileMgmt
{

public:
CFileMgmt(void);
~CFileMgmt(void);
int GetFileNumber(void);
CString GetFileName(int nFileIndex);

int AddOpenedFileToCfg(CString strFileName);
int DelOpenedFileFormCfg(CString strFileName);
// int loadOpenedFileList(deque <long> a);

private:
int FindNoteFile(int &nFileNumber, int nFileIndex, CString &strFileName);
public:
BOOL IsExistFile(CString strFileName);
};

#endif


我这么写不行,一样报错!
yintongshun 2004-03-19
  • 打赏
  • 举报
回复
#include <queue>
using namespace std;

注意上面的要在
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif之前

然后就可以用了
std::deque <long > de;//std省略应该也可以,你试试
ymbymb 2004-03-19
  • 打赏
  • 举报
回复
#include <deque>

void main()
{
deque<long> a;
}

vc6 compile pass!
快乐鹦鹉 2004-03-19
  • 打赏
  • 举报
回复
这个deque的原型是怎样的啊?
yj_nj 2004-03-19
  • 打赏
  • 举报
回复
没有吧!
快乐鹦鹉 2004-03-19
  • 打赏
  • 举报
回复
有没有大小写区分啊?
yj_nj 2004-03-19
  • 打赏
  • 举报
回复
我在UNIX下可以用的啊,在VC下怎么不行了!奇怪!哪位高手在VC下用过啊?
快乐鹦鹉 2004-03-19
  • 打赏
  • 举报
回复
deque的模板类是怎么说的?
yj_nj 2004-03-19
  • 打赏
  • 举报
回复
我是这样写的:
{
deque<long> a;
}

它老是报这个错:error C2061: 语法错误 : 标识符“deque”

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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