Click to See Complete Forum and Search --> : what is the replacement to scanf in managed c++/cli


t.jalaja
September 23rd, 2010, 06:38 AM
hello i want to know the replacement of sscanf, sprintf in managed c++/cli

thanks in advance

Eri523
September 23rd, 2010, 12:50 PM
The "real .NET way" of doing console I/O is using the System::Console (http://msdn.microsoft.com/en-us/library/system.console.aspx) class. AFAIK there is, however, no direct .NET equivalent to scanf() (mentioned in the title of the thread). You would have to use the Console::Read...() members to read in character strings and then convert them using the .Parse() members that several of the .NET types offer, like this one (http://msdn.microsoft.com/en-us/library/b3h1hf19.aspx) for instance.

An equivalent of sprintf(), like you asked for in the body of your post, can be the String::Format() method (http://msdn.microsoft.com/en-us/library/system.string.format(VS.80).aspx). Again, there's no direct equivalent to sscanf(), but you can use the .Parse() members of the individual types already mentioned above.

Aside from that, you can also use C++ runtime classes or functions in C++/CLI, including iostreams, sscanf() and sprintf(). They don't have direct support for the .NET-specific types though.

HTH