Is there any C/C++ system() function accepting unicode?
Question: In C/C++, is there any system function that accepts Unicode ? See below for reason:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[])
{
// http://stackoverflow.com/questions/3313332/bringing-another-apps-window-to-front-on-mac-in-c
system("osascript -e \"tell application \\\"Address Book\\\" to activate\"");
re开发者_开发知识库turn EXIT_SUCCESS;
}
Use _wsystem
.
_wsystem
is a wide-character version of system
; the command argument to _wsystem
is a wide-character string. These functions behave identically otherwise.
http://msdn.microsoft.com/en-us/library/277bwbdz.aspx
A special function named main
is the starting point of execution for all C and C++ programs. If you are writing code that adheres to the Unicode programming model, you can use wmain
, which is the wide-character version of main.
http://msdn.microsoft.com/en-us/library/vstudio/6wd819wh.aspx
system() does not care about the encoding as far as I know, it should just pass it through.
maybe your question is "how to type a UTF-8 string literal in C", or "what encoding does osascript expect"?
the portable way to do UTF-8 in C is with \x escape sequences, though if you are willing to rely on C99 or a specific compiler you can often type the UTF-8 directly.
I would guess osascript expects UTF-8 though I have no real idea.
Standard C and C++ do not explicitly understand Unicode at all: none of the standard APIs are defined as accepting or returning Unicode strings. Unlike Java. Whether a wide string or multibyte string is actually a Unicode encoded string is system dependent. So the simple answer is no.
精彩评论