以下程序,在没有设置 UNICODE和_UNICODE 时编译通过,但我是project->setting->preprocessor definitions中加了UNICODE,_UNICODE后编译不通过出错信息是(就是 cin >> volumeName; 这一行出错)--------------------Configuration: TEST - Win32 Debug--------------------
Compiling...
StdAfx.cpp
Compiling...
TEST.cpp
D:\My Project\TEST\TEST.cpp(15) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'unsigned short [260]' (or there is no acceptable conversion)
Error executing cl.exe.TEST.exe - 1 error(s), 0 warning(s)-------------------------------------------// TEST.cpp : Defines the entry point for the console application.
//#include "stdafx.h"
#include <windows.h>
#include <iostream.h>int main(int argc, char* argv[])
{
BOOL success;
TCHAR volumeName[MAX_PATH]; cout << TEXT("输入新的 C 盘卷标: ");
cin >> volumeName; success = SetVolumeLabel(TEXT("c:\\" ), volumeName);
if (success)
cout << TEXT("成功\n");
else
cout << TEXT("错误代码:") << GetLastError() << endl;
return 0;
}
Compiling...
StdAfx.cpp
Compiling...
TEST.cpp
D:\My Project\TEST\TEST.cpp(15) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'unsigned short [260]' (or there is no acceptable conversion)
Error executing cl.exe.TEST.exe - 1 error(s), 0 warning(s)-------------------------------------------// TEST.cpp : Defines the entry point for the console application.
//#include "stdafx.h"
#include <windows.h>
#include <iostream.h>int main(int argc, char* argv[])
{
BOOL success;
TCHAR volumeName[MAX_PATH]; cout << TEXT("输入新的 C 盘卷标: ");
cin >> volumeName; success = SetVolumeLabel(TEXT("c:\\" ), volumeName);
if (success)
cout << TEXT("成功\n");
else
cout << TEXT("错误代码:") << GetLastError() << endl;
return 0;
}
#include <iostream.h>
int main(int argc, char* argv[])
{
TCHAR str[MAX_PATH];
cin>>(char*)str;
cout<<endl; cout<<str<<endl;
return 0;
}
#include <windows.h>
#include <iostream.h>
int main(int argc, char* argv[])
{
BOOL success;
TCHAR str[MAX_PATH];
cout << TEXT("输入新的 C 盘卷标: ");
cin>>TEXT(str);
cout<<endl;
success = SetVolumeLabel(TEXT("c:\\" ), str); if (success)
cout << TEXT("成功\n");
else
cout << TEXT("错误代码:") << GetLastError() << endl;
return 0;
}