Quantcast
Channel: Visual Studio General Questions forum
Viewing all articles
Browse latest Browse all 21115

Different behavior between VS2010 and VS2012 (decimal symbol in printf/scanf, CString.Format,...)

$
0
0
#include <locale.h>
#include <tchar.h>
#include <string>
#include <iostream>

#include <atlstr.h>

int main()
{
	std::wstring wstr = _tsetlocale(LC_ALL, _T("French"));
	std::wcout << wstr << std::endl;

	TCHAR text[10];
	swprintf_s(text, 10, _T("%lf"), 1.1);	

	std::wcout << text << std::endl;

	CString str;
	str.Format(_T("%lf"), 1.1);
	std::wcout << str.GetBuffer() << std::endl;

	double d1;
	sscanf_s("1.1", "%lf", &d1);
	double d2;
	sscanf_s("1,1", "%lf", &d2);
	std::cout << d1 << "   " << d2 << std::endl;
	return 0;
}

In my Win7 OS, the Format option in "Region and Language" is set to French(France), but in Additional Settings, the decimal symbol is set to '.'

Compiling above code in VS2010, the result is:

French_France.1252
1.100000
1.100000
1.1   1

But in VS2012, the result is:

French_France.1252
1,100000
1,100000
1   1.1

It seems in VS2010, scanf/printf and CString.Format are using the user-defined decimal symbol in Additional Setting, but in VS2012, Additional Setting is not used.

What can I do to get the same result with VS2010 in VS2012?

Better have a global option.

Thanks


Viewing all articles
Browse latest Browse all 21115

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>