2011-06-01 5 views
4

私はVS2010のMicrosoft VC++でC++を始めました。私は最近、いくつかの仕事を見つけましたが、RHEL 5をGCCで使っています。私のコードは主にネイティブのC++ですが、私は1つのことに気付きました。GCCのタプルテンプレート

GCCは<tuple>ヘッダーファイルまたはタプルテンプレートを認識しません。最初は、cplusplus.comを見て、ヘッダーが本当に標準ライブラリの一部ではないことがわかるまで、それはちょうどタイプミスかもしれません。

問題は、環境がEclipseやネットビーンより優れていて審美的に快適であり、デバッグが簡単であるため、私のコードをVisual Studioに書きたいということです。問題は、タプルを使用するコードをすでに作成していて、コードが本当に好きです。この問題にどうしたらいいですか?ここで

は私のコードです:

using std::cout; 
using std::make_tuple; 
using std::remove; 
using std::string; 
using std::stringstream; 
using std::tolower; 
using std::tuple; 
using std::vector; 

// Define three conditions to code 
enum {DONE, OK, EMPTY_LINE}; 
// Tuple containing a condition and a string vector 
typedef tuple<int,vector<string>> Code; 


// Passed an alias to a string 
// Parses the line passed to it 
Code ReadAndParse(string& line) 
{ 

    /***********************************************/ 
    /****************REMOVE COMMENTS****************/ 
    /***********************************************/ 
    // Sentinel to flag down position of first 
    // semicolon and the index position itself 
    bool found = false; 
    size_t semicolonIndex = -1; 

    // Convert the line to lowercase 
    for(int i = 0; i < line.length(); i++) 
    { 
     line[i] = tolower(line[i]); 

     // Find first semicolon 
     if(line[i] == ';' && !found) 
     { 
      semicolonIndex = i; 
      // Throw the flag 
      found = true; 
     } 
    } 

    // Erase anything to and from semicolon to ignore comments 
    if(found != false) 
     line.erase(semicolonIndex); 


    /***********************************************/ 
    /*****TEST AND SEE IF THERE'S ANYTHING LEFT*****/ 
    /***********************************************/ 

    // To snatch and store words 
    Code code; 
    string token; 
    stringstream ss(line); 
    vector<string> words; 

    // A flag do indicate if we have anything 
    bool emptyLine = true; 

    // While the string stream is passing anything 
    while(ss >> token) 
    { 
     // If we hit this point, we did find a word 
     emptyLine = false; 

     // Push it onto the words vector 
     words.push_back(token); 
    } 

    // If all we got was nothing, it's an empty line 
    if(emptyLine) 
    { 
     code = make_tuple(EMPTY_LINE, words); 
     return code; 
    } 


    // At this point it should be fine 
    code = make_tuple(OK, words); 
    return code; 
} 

は、コンパイラの互換性がないから私のコードを保存するためにとにかくはありますか?

+3

''タイプが今後の改訂Cの一部であるにブーストライブラリのバージョンを使用することができ、移植のためのコースのうち

#include <tr1/tuple.hpp> //... std::tr1::tuple<int, int> mytuple; 

++言語をC++ 0xに変更しようとするとg ++でサポートされる可能性があります。これがうまくいくかどうかはわかりませんが、おそらくこれが問題の原因です。 – templatetypedef

+3

つまり、 'g ++ -std = C++ 0x'を試してください。 – Nemo

+0

@Nemo明日はそれを試してみますが、今のところ私はペアを使ってうれしく思います。ありがとう。 – sj755

答えて

1

限り、それはあなたが

typedef pair<int,vector<string>> Code; 

を使用することができます。しかし、私はタプルは、標準C++(それはTR1、その結果、標準C++ 0xの中に含まれて判明)であるとは思わないだけのペアだと。いつものようにBoostはあなたをカバーしました。したがって、以下を含む:

#include "boost/tuple/tuple.hpp" 

コンパイラ間で問題を解決します。 TR1ライブラリを出荷

+0

もちろん、私はタプルを使いましたので、2つの要素がペアに含まれることを忘れてしまいました。 – sj755

1

コンパイラは、ここではそれが必要あなたがその間