dginley

I have a fairly small project that builds and runs under VS 2003. But when I convert it to VS 2005, it no longer builds. I'm now getting error C2039: 'sprintf_s' : is not a member of "global namespace"

The message points to line 966 in a file named xlocnum in C:\Program Files\Microsoft Visual Studio 8\VC\include.

I searched the equivalent file in the VS 2003 folder, and there is no mention of sprintf_s.

I may be missing something that should be obvious, but it looks like a Microsoft compiler is refusing to compile Microsoft code.

I'm running on XP SP2, VS 2005 Professional with SP1.

Thanks for any insight,
Dennis


Re: Visual C++ General sprintf_s is not a member of global namespace

Pintu Shukla


As Error is point out that 'identifier1' : is not a member of 'identifier2'.Try to use System:Tongue Tiedtring::Format. instead of s_printf_s
any way have a look on this Article. And if Possible Show your code here

Visual Studio 2005 is deprecating our favorite standard C functions



Thanx





Re: Visual C++ General sprintf_s is not a member of global namespace

Jonathan Caves - MSFT

How does suggesting using System:: String help The code that compiles with Visual C++ 2003 works with sprintf_s and the same code should continue to compiler with Visual C++ 2005.

To the OP: would it be possible to show some code Are you explicitly including stdio.h yourself






Re: Visual C++ General sprintf_s is not a member of global namespace

dginley

I neglected to mention that this is a C++ project, so String.Format isn't an option. Also, I'm not using sprintf_s anywhere, although I am using sprintf in a few places.

The error message points to Microsoft code, not mine. The file is C:\Program Files\Microsoft Visual Studio 8\VC\include\xlocnum, and the offending code starts on line 960, here:

Code Block

_VIRTUAL _OutIt __CLR_OR_THIS_CALL do_put(_OutIt _Dest,

ios_base& _Iosbase, _Elem _Fill, long _Val) const

{ // put formatted long to _Dest

const size_t _Buf_size = 2 * _MAX_INT_DIG;

char _Buf[_Buf_size], _Fmt[6];

return (_Iput(_Dest, _Iosbase, _Fill, _Buf,

::sprintf_s(_Buf, _Buf_size, _Ifmt(_Fmt, "ld",

_Iosbase.flags()), _Val)));

}

The error message sounds to me like it sees this reference to sprintf, but can't find its definition in the global namespace. Maybe I need to include a VS 2005 specific library

Thanks for the replies,

Dennis





Re: Visual C++ General sprintf_s is not a member of global namespace

Simple Samples

See the Requirements in sprintf_s, _sprintf_s_l, swprintf_s, _swprintf_s_l (CRT). Did you include the required haeder






Re: Visual C++ General sprintf_s is not a member of global namespace

Simple Samples

Pintu Shukla wrote:
Visual Studio 2005 is deprecating our favorite standard C functions

sprintf_s is not deprecated.






Re: Visual C++ General sprintf_s is not a member of global namespace

dginley

See the Requirements in sprintf_s, _sprintf_s_l, swprintf_s, _swprintf_s_l (CRT). Did you include the required haeder

Yes, I'm including stdio.h, and even copied it to the local folder to be sure I'm grabbing the right one, and not the one from VS 2003. I still see the error.

Dennis





Re: Visual C++ General sprintf_s is not a member of global namespace

Simple Samples

The easiest and most effective way to verify what header is included is to right-click in the filename in the #include and then in the context menu select the option fo open the file. That will open the same file that the compiler would use.

I suggest undoing everything you have done such as copying system headers locally. One reason is because it is often easy to overlook things like that when problems occur and then the problem can be difficult to diagnose. Another reason is that it makes it difficult or impossible for others such as I to help you. If you don't know where to look to view and modify the #include directories then it is important you look there.

Perhaps it will help if you show the relevant code; probably just the portion of your program that has the #includes. If there is a stdafx.h then post the contents of that.






Re: Visual C++ General sprintf_s is not a member of global namespace

dginley

I solved my problem by adding C:\Program Files\Microsoft Visual Studio 8\VC\include at the top of the additional includes list for the project. Now when I right click and open stdio.h from the #include line, the correct file opens. The project now compiles. I'm getting link errors, but that's to be expected when moving from one version of VS to another.

Thanks for all the help and advice.

Dennis





Re: Visual C++ General sprintf_s is not a member of global namespace

Simple Samples

Yes, sounds like you are in good shape.

There is also a list of include directories in the VS options. Perhaps that needs to be fixed. The options also has a list of directories for libraries.