私は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;
}
は、コンパイラの互換性がないから私のコードを保存するためにとにかくはありますか?
''タイプが今後の改訂Cの一部であるにブーストライブラリのバージョンを使用することができ、移植のためのコースのうち
++言語をC++ 0xに変更しようとするとg ++でサポートされる可能性があります。これがうまくいくかどうかはわかりませんが、おそらくこれが問題の原因です。 – templatetypedef
つまり、 'g ++ -std = C++ 0x'を試してください。 – Nemo
@Nemo明日はそれを試してみますが、今のところ私はペアを使ってうれしく思います。ありがとう。 – sj755