2013-11-20 17 views
1

我嘗試創建一個區域與下面的代碼行:VC6 - 如何用用戶定義的方面創建一個std :: locale?

std::locale loc(std::locale::classic(), new comma); 

comma的定義是:

struct comma : std::numpunct<char> { 
    char do_decimal_point() const { return ','; } 
}; 

我認爲它應該工作,因爲我看到MSDN文檔中類似的構造函數調用到facet。不幸的是我得到的錯誤:

error C2664: '__thiscall std::locale::std::locale(const char *,int)' : cannot convert parameter number 1 from 'const class std::locale' in 'const char *'

你知道嗎,我該怎麼做纔對嗎?

在Stackoverflow上有一些答案,這樣做就是這樣(thisthis one)。但似乎舊的VC6編譯器不支持此構造函數(儘管VC6文檔中的示例使用它)。但是必須有一種方法來使用VC6的方面,否則它不會成爲文檔的一部分。

+0

你約爲VC6 _very_樂觀。我很驚訝仍然有MSDN文檔,但它肯定不再受支持。即如果文檔錯誤,Microsoft不會修復它。 – MSalters

+0

@MSalters:我對參與計算的人stackoverflow.com持樂觀態度,經常沒有得到有用的答案,但不幸的是,沒有人能夠深入挖掘VC6部分。 –

+1

好吧,有更多的人在努力恢復渡渡鳥,而不是那些希望看到VC6迴歸的人。 – MSalters

回答

1

要使用用戶定義的方面創建std :: locale,我們可以使用_ADDFAC。在documentation to the locale constructor我發現這是很有幫助的提示:

[...] you should write _ADDFAC(loc, Facet) to return a new locale that adds the facet Facet to the locale loc , since not all translators currently support the additional template constructors

VC6似乎並不支持額外的模板的構造函數。

示例代碼:

std::istringstream iss("333,444"); // comma is decimal mark 
std::locale loc(std::_ADDFAC(iss.getloc(), new comma)); 
iss.imbue(loc); 
iss >> e; 
std::cout << e << std::endl; // prints 333.444 
+0

該編譯器的最佳源代碼仍然是1998年或1999年的獨立MSDN安裝(你不能安裝在win 7 64位:()上。這些年來MSDN文檔上的編輯改寫過去,因爲VC6的工作原理與緩慢編譯器因爲很多部分的實現,編寫STL和VC6很費力 – ColdCat

+0

你說得對,VC6在我的機器上運行在一個虛擬的32位XP環境下,我需要它來做一些舊的大型項目,他們成爲一個新的IDE。缺點是,我必須小心使用VC6的STL。 –

相關問題