2016-02-28 135 views
-2

之前,我很新的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,[email protected]{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 = "ABCDEGFHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/"; 

    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 
+2

其他文件('Helper.h','KeyConstants.h','Base64.h')的内容是什么? –

+0

这个错误可能在头文件中 –

+2

我预测'Base64.h'末尾有个问题 - 可能缺少一个分号。 –

回答

-1

你在Base64.hext/alloc_traits.h或像其他.h文件的一个结尾缺少一个分号
可能KeyConstants.h

+2

好的答案说明明显 –

+0

我加了“Base64.h”,所以你可以看看它 – nhabbott

+1

你为什么低调,伙计们?这样的问题,这样的答案。 – Victor

0

检查“KeyConstants.h”文件。不要忘记“;”在地图的尽头。 (其中有一个键列表)