gpt4 book ai didi

c++ - 使用标准集时的一些问题

转载 作者:行者123 更新时间:2023-11-28 08:16:57 24 4
gpt4 key购买 nike

所有,我已经创建了以下代码:

struct Styles{
wstring styleVal;
wstring styleName;
};
set<Styles> vtrStyles1;//filled in somehow
set<Styles> vtrStyles2;//filled in somehow

set<Styles> vtrStyles3(vtrStyles1);
vtrStyles3.insert(vtrStyles2.begin(), vtrStyles2.end());
unCommon = vtrStyles1.size() + vtrStyles2.size() - vtrStyles3.size();

我在 stdafx.h 中包含了 set,并使用了 namespace std;但我收到以下错误:

1>XMLDOMFromVCDlg.cpp(5377): error C2065: 'set' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5377): error C2275: 'Styles' : illegal use of this type as an expression
1> XMLDOMFromVCDlg.cpp(5344) : see declaration of 'Styles'
1>XMLDOMFromVCDlg.cpp(5377): error C2065: 'vtrStyles1' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5378): error C2065: 'set' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5378): error C2275: 'Styles' : illegal use of this type as an expression
1> XMLDOMFromVCDlg.cpp(5344) : see declaration of 'Styles'
1>XMLDOMFromVCDlg.cpp(5378): error C2065: 'vtrStyles2' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5497): error C2065: 'vtrStyles1' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5497): error C2228: left of '.insert' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5507): error C2065: 'vtrStyles1' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5507): error C2228: left of '.insert' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5517): error C2065: 'vtrStyles1' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5517): error C2228: left of '.insert' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5534): error C2065: 'vtrStyles1' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5534): error C2228: left of '.insert' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5545): error C2065: 'vtrStyles1' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5545): error C2228: left of '.insert' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5555): error C2065: 'vtrStyles1' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5555): error C2228: left of '.insert' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5565): error C2065: 'vtrStyles1' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5565): error C2228: left of '.insert' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5606): error C2065: 'vtrStyles2' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5606): error C2228: left of '.insert' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5616): error C2065: 'vtrStyles2' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5616): error C2228: left of '.insert' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5626): error C2065: 'vtrStyles2' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5626): error C2228: left of '.insert' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5643): error C2065: 'vtrStyles2' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5643): error C2228: left of '.insert' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5654): error C2065: 'vtrStyles2' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5654): error C2228: left of '.insert' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5664): error C2065: 'vtrStyles2' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5664): error C2228: left of '.insert' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5674): error C2065: 'vtrStyles2' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5674): error C2228: left of '.insert' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5704): error C2065: 'set' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5704): error C2275: 'Styles' : illegal use of this type as an expression
1> XMLDOMFromVCDlg.cpp(5344) : see declaration of 'Styles'
1>XMLDOMFromVCDlg.cpp(5704): error C2065: 'vtrStyles1' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5704): error C3861: 'vtrStyles3': identifier not found
1>XMLDOMFromVCDlg.cpp(5705): error C2065: 'vtrStyles3' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5705): error C2228: left of '.insert' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5705): error C2065: 'vtrStyles2' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5705): error C2228: left of '.begin' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5705): error C2065: 'vtrStyles2' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5705): error C2228: left of '.end' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5706): error C2065: 'vtrStyles1' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5706): error C2228: left of '.size' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5706): error C2065: 'vtrStyles2' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5706): error C2228: left of '.size' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5706): error C2065: 'vtrStyles3' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5706): error C2228: left of '.size' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5707): error C2065: 'vtrStyles3' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5707): error C2228: left of '.size' must have class/struct/union
1> type is ''unknown-type''

所以这是怎么回事?提前致谢。

干杯

岱岳

最佳答案

有些事情您没有告诉我们。如果您定义 operator<,则以下程序(从您发布的代码中按部分复制粘贴)可以使用 Visual Studio 2008 进行编译。为你的 Styles结构(见下文)。

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

struct Styles {
wstring styleVal;
wstring styleName;
};

int main ( int, char ** )
{
set<Styles> vtrStyles1;
set<Styles> vtrStyles2;
set<Styles> vtrStyles3(vtrStyles1);
vtrStyles3.insert(vtrStyles2.begin(), vtrStyles2.end());
const size_t unCommon =
vtrStyles1.size() + vtrStyles2.size() - vtrStyles3.size();
}

以下定义对我来说似乎没问题,但它可能不是您想要的。在 main() 之前插入这个.

bool operator< ( const Styles& lhs, const Styles& rhs )
{
return (lhs.styleName < rhs.styleName);
}

如果你能编译这个程序,那么你的问题就出在别处。

关于c++ - 使用标准集时的一些问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7424056/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com