0

What is the alternative C++ function for _tprintf in win32 api. I have found a lot of things in Charles Petzold Book for Windows Programming that C++ Standard doesn't include, because it is written in C. Will the use of C functions in C++ programs will be legal according to standard.

PS: I know that C++ is a superset of C, but there are a lot of thing which are different in both of them.

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
user1162272
  • 31
  • 1
  • 6
  • 1
    Note that if you couldn't use `__tprintf()` because it is written in C, then you couldn't use any of the Win32 API at all (since it's also written in C). – André Caron Jan 22 '12 at 18:28
  • It was useful in the previous century when there were still non-Unicode operating systems. That's over and done with, the floppy disk drive on the last working Windows 98 machine died a year ago. Use wprintf() instead. – Hans Passant Jan 22 '12 at 18:49
  • [**C++ is not a superset of C**](http://stackoverflow.com/q/1201593/78845)! – johnsyweb Feb 06 '12 at 21:09

3 Answers3

2

Since your Question specifically asks about standard supported unicode api, the answer is:

The Standard does not provide any. So, there is no portable ready to use api for this. You will have to write your own implementation which opens the stream in binary mode and read/write byte by byte.

Alok Save
  • 202,538
  • 53
  • 430
  • 533
  • I wasn't the person who downvoted, but I think this answer is incomplete. Yes, they asked about standard C++ Unicode functions, but they're clearly also talking about the Win32 API. So if there is a function for this purpose provided by the Windows API, it would be more useful to suggest that one rather than to suggest that they write their own implementation. – Cody Gray - on strike Jan 24 '12 at 03:32
  • @CodyGray: I don't know whether I misread the Q or it was edited later,but I remember reading it as asking for a standard compliant replacement for `_tprintf` and hence the suggestion. In either ways, a unexplained downvote like this is not helping anybody. – Alok Save Jan 24 '12 at 03:40
1

You can use most C functions in C++. Certainly you can use anything in the win32 api.

PS: C++ is not a subset of C, but C is a near subset of C++.

Benjamin Lindley
  • 101,917
  • 9
  • 204
  • 274
  • Ok. If I use both C and C++ in win32 api program, would i be able to use features of C++ like STL, Classes etc – user1162272 Jan 22 '12 at 18:29
  • @user1162272: Yes, absolutely. – Benjamin Lindley Jan 22 '12 at 18:29
  • 1
    @user1162272: just be aware that there are some limitations of using C++ features in a Win32 environment: notably any Win32 callbacks - like an EnumWindowsProc or a WindowProc or DialogProc - should not emit C++ exceptions; worth keeping in mind given that some STL classes will throw exceptions in certain cases. In general, you can use C++ features however you like within your own code, but are limited to the C subset when working with the actual Win32 APIs. – BrendanMcK Jan 23 '12 at 23:58
0

A safe C++ alternative for tprintf() would be wprintf_s().

int wprintf_s(const wchar_t *format [,argument]...);
jdw
  • 5,727
  • 1
  • 15
  • 8