我对C ++很新,我不知道为什么但是每当我尝试运行我的程序时,我都会收到以下错误:
error: expected ', ' or ' ;' before 'namespace'
我很确定下面文件中的using namespace std;
行导致了问题,但我不确定如何修复它。
Main.cpp的
#include <iostream>
#include <windows.h>
#include "Helper.h"
#include "KeyConstants.h"
#include "Base64.h"
using namespace std;
int main()
{
MSG Msg;
while(GetMessage (&Msg, NULL, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return 0;
}
它还会打开一个名为stl_construct.h
的文件,并告诉我错误来自该文件中的namespace std _GLIBCXX_VISIBILITY(default)
。我很确定这不是问题,但万一我会添加一些。
摘录自stl_construct.h
:
#ifndef _STL_CONSTRUCT_H
#define _STL_CONSTRUCT_H 1
#include <new>
#include <bits/move.h>
#include <ext/alloc_traits.h>
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
/**
* Constructs an object in existing memory by invoking an allocated
* object's constructor with an initializer.
*/
#if __cplusplus >= 201103L
template<typename _T1, typename... _Args>
inline void
_Construct(_T1* __p, _Args&&... __args)
{ ::new(static_cast<void*>(__p)) _T1(std::forward<_Args>(__args)...); }
#else
template<typename _T1, typename _T2>
inline void
_Construct(_T1* __p, const _T2& __value)
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 402. wrong new expression in [some_]allocator::construct
::new(static_cast<void*>(__p)) _T1(__value);
}
#endif
Base64.h
#ifndef BASE64_H
#define BASE64_H
#include <vector>
#include <string>
namespace Base64
{
std::string base64_encode(const std::string &);
const std::string &SALT1 = "LM::&&jARLZ_E5?u ;f9+,4AZwA8MF3t(t+T+ {o!g,Ze22Pu&6$GbROk-* LzIxb?d'";
const std::string &SALT2 = "'hytO|-h0,Rb@6Z{iH=H=+Q:E{+Y:&<rzP!^;oIC!.OGk5o6)^S^1-o,UcLt(`kQx'?";
const std::string &SALT3 = "FU%^L,RHo({KD~[iZ/7Y%EehTkaE6^jwYQXwR#5Qh|c?)m?CGC(j-&oG~laZclg?Q'!";
std::string EncryptB64(std::string s)
{
s = SALT1 + s + SALT3 + SALT2;
s = base64_encode(s);
s.insert(15, SALT1);
s += SALT3;
s = base64_encode(s);
s = SALT3 + SALT1 + SALT2;
s = base64_encode(s);
s.insert(7, "t");
s.insert(1, SALT3);
return s;
}
const std::string &BASE64_CODES = "ABCDEGFHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
std::string base64_encode(const std::string &s)
{
std::string ret;
int val = 0;
int bits = -6;
const unsigned int b63 = 0x3F;
for(const auto &c : s)
{
val = (val << 8) + c;
bits += 8;
while(bits >= 0)
{
ret.push_back(BASE64_CODES[(val >> bits) & b63]);
bits -= 6;
}
}
if(bits > -6)
ret.push_back(BASE64_CODES[((val << 8) >> (bits + 8)) & b63]);
while(ret.size()%4)
ret.push_back('=');
return ret;
}
}
#endif // BASE_64
答案 0 :(得分:0)
检查“KeyConstants.h”文件。别忘了“;”在地图的最后。 (那个有密钥列表的那个)
答案 1 :(得分:-1)
你错过了分号
可能在Base64.h
或ext/alloc_traits.h
或其他.h文件的末尾,例如KeyConstants.h