1 ------------------------------------ ------------- DWORD x = 23; LONG aa = 16; 字符串* buf; ofstream PPTfile(" PPT.txt",ios :: out); PPTfile<< "进程ID = 0x << x.ToString(" X8")<< endl; PPTfile<< " ref count(c)= 0x << x.ToString(" X4")<< endl; PPTfile<< "线程数= << x.ToString()<< endl; PPTfile<< "父进程ID = 0x << x.ToString(" X8")<< endl; PPTfile<< "优先基数= << aa.ToString()<< endl; buf = x.ToString(" X8"); PPTfile<< "进程ID = 0x << buf<< endl; buf = x.ToString(" X4"); PPTfile<< " ref count(c)= 0x << buf<< endl; buf = x.ToString(); PPTfile<< "线程数= << buf<< endl; buf = x.ToString(" X8"); PPTfile<< "进程ID = 0x << buf<< endl; buf = aa.ToString(); PPTfile<< "优先基数= << buf<< endl; buf = String :: Concat(S" Process ID = 0x",x.ToString(" X8")); PPTfile< ;< buf<< endl; buf = String :: Concat(S" ref count(c)= 0x",x.ToString(" X4")); PPTfile< < buf<< endl; buf = String :: Concat(S" Thread Count =",x.ToString()); PPTfile<< buf<< endl; buf = String :: Concat(S" parent process ID = 0x",x.ToString(" X8")); PPTfile<< buf<< endl; buf = String :: Concat(S" Priority Base =",aa.ToString()); PPTfile<< buf<< endl; PPTfile.close(); 解决方案 Howard Kaikow写道: In下面的代码,所有以PPTfile开头的行<<在构建时收到以下错误。 " // i:\ C ++ \ C ++ Code \ FileOperations\Form1.h(127):警告C4800 :''System :: String __gc *'':强制值为bool''true''或''false''(性能警告) 我得到以下输出,这显然是错误的: ToString返回一个.NET对象句柄,本机C ++无法处理, 因此它试图将其隐式转换为bool。因此 警告。您必须使用以下函数(作为示例) 将托管字符串转换为非托管字符串: std :: wstring ToUnmanagedString(System :: String * str) { const wchar_t __pin * c_str = PtrToStringChars(str); return std :: wstring(c_str); } 另外,你不应该使用endl,你应该使用\ n代替。 endl 刷新流,这是一个严重的性能损失。 Tom Thanx。 - http://www.standards.com/; 请参阅Howard Kaikow的网站。 " Tamas Demjen" < TD ***** @ yahoo.com>在消息中写道 新闻:ej ************** @ tk2msftngp13.phx.gbl ... Howard Kaikow写道:在下面的代码中,所有以PPTfile开头的行<<在构建时获得以下错误。 " // i:\ C ++ \ C ++ Code\FileOperations\Form1.h(127):警告C4800 :''System :: String __gc *'':强制值为bool''true''或''false''(性能警告) 我得到以下输出,这显然是错误的: ToString返回一个.NET对象句柄,本机C ++无法处理,因此它尝试转换它含蓄地bool。因此警告。您必须使用以下函数(作为示例)将托管字符串转换为非托管字符串: std :: wstring ToUnmanagedString(System :: String * str) { const wchar_t __pin * c_str = PtrToStringChars(str); 返回std :: wstring(c_str); } 另外,你不应该使用endl,你应该使用\ n代替。 endl 刷新流,这是一个严重的性能损失。 Tom " Tamas Demjen" < TD ***** @ yahoo.com>在消息中写道 news:ej ************** @ tk2msftngp13.phx.gbl ... ToString返回一个.NET对象句柄,本机C ++无法处理,因此它试图将其隐式转换为bool。因此警告。您必须使用以下函数(作为示例)将托管字符串转换为非托管字符串: std :: wstring ToUnmanagedString(System :: String * str) { const wchar_t __pin * c_str = PtrToStringChars(str); 返回std :: wstring(c_str); } 使用以上,我得到了错误: i:\ C ++ \ C ++ Code\FileOperations\Form1.h(101):错误C2230:''ToUnmanagedString'' :托管类的成员函数不能返回非托管类或 struct''std :: basic_string< _Elem,_Traits,_Ax>''除非它是一个总计 ,含 [ _Elem = wchar_t, _Traits = std :: char_traits< wchar_t> , _Ax = std :: allocator< wchar_t> ] 这是什么意思? In the code below, ALL the lines that start with PPTfile << are getting thefollowing error at build time. "//i:\C++\C++Code\FileOperations\Form1.h(127) : warning C4800:''System::String __gc *'' : forcing value to bool ''true'' or ''false''(performance warning)" I get the following output, which is obviously wrong: Process ID = 0x1ref count (c) = 0x1Thread Count = 1parent process ID = 0x1Priority Base = 1Process ID = 0x1ref count (c) = 0x1Thread Count = 1Process ID = 0x1Priority Base = 111111-------------------------------------------------DWORD x = 23;LONG aa = 16; String *buf;ofstream PPTfile("PPT.txt", ios::out);PPTfile << " Process ID = 0x" << x.ToString("X8") << endl;PPTfile << " ref count (c) = 0x" << x.ToString("X4") << endl;PPTfile << " Thread Count = " << x.ToString() << endl;PPTfile << " parent process ID = 0x" << x.ToString("X8") << endl;PPTfile << " Priority Base = " << aa.ToString() << endl; buf = x.ToString("X8");PPTfile << " Process ID = 0x" << buf << endl;buf = x.ToString("X4");PPTfile << " ref count (c) = 0x" << buf << endl;buf = x.ToString();PPTfile << " Thread Count = " << buf << endl;buf = x.ToString("X8");PPTfile << " Process ID = 0x" << buf << endl;buf = aa.ToString();PPTfile << " Priority Base = " << buf << endl; buf = String::Concat(S" Process ID = 0x", x.ToString("X8"));PPTfile << buf << endl;buf = String::Concat(S" ref count (c) = 0x", x.ToString("X4"));PPTfile << buf << endl;buf=String::Concat(S" Thread Count = ", x.ToString());PPTfile << buf << endl;buf=String::Concat(S" parent process ID = 0x", x.ToString("X8"));PPTfile << buf << endl;buf =String::Concat(S" Priority Base = ", aa.ToString());PPTfile << buf << endl;PPTfile.close(); 解决方案 Howard Kaikow wrote: In the code below, ALL the lines that start with PPTfile << are getting the following error at build time. "//i:\C++\C++Code\FileOperations\Form1.h(127) : warning C4800: ''System::String __gc *'' : forcing value to bool ''true'' or ''false'' (performance warning)" I get the following output, which is obviously wrong: ToString returns a .NET object handle, which native C++ can''t handle,and therefore it tries to convert it implicitly to bool. Thus thewarning. You have to use the following function (as an example) toconvert managed strings to unmanaged ones: std::wstring ToUnmanagedString(System::String* str){const wchar_t __pin* c_str = PtrToStringChars(str);return std::wstring(c_str);} In addition, you shouldn''t use endl, you should use "\n" instead. endlflushes the stream, which is a serious performance penalty. TomThanx. -- http://www.standards.com/; See Howard Kaikow''s web site."Tamas Demjen" <td*****@yahoo.com> wrote in messagenews:ej**************@tk2msftngp13.phx.gbl... Howard Kaikow wrote: In the code below, ALL the lines that start with PPTfile << are gettingthe following error at build time. "//i:\C++\C++Code\FileOperations\Form1.h(127) : warning C4800: ''System::String __gc *'' : forcing value to bool ''true'' or ''false'' (performance warning)" I get the following output, which is obviously wrong: ToString returns a .NET object handle, which native C++ can''t handle, and therefore it tries to convert it implicitly to bool. Thus the warning. You have to use the following function (as an example) to convert managed strings to unmanaged ones: std::wstring ToUnmanagedString(System::String* str) { const wchar_t __pin* c_str = PtrToStringChars(str); return std::wstring(c_str); } In addition, you shouldn''t use endl, you should use "\n" instead. endl flushes the stream, which is a serious performance penalty. Tom"Tamas Demjen" <td*****@yahoo.com> wrote in messagenews:ej**************@tk2msftngp13.phx.gbl... ToString returns a .NET object handle, which native C++ can''t handle, and therefore it tries to convert it implicitly to bool. Thus the warning. You have to use the following function (as an example) to convert managed strings to unmanaged ones: std::wstring ToUnmanagedString(System::String* str) { const wchar_t __pin* c_str = PtrToStringChars(str); return std::wstring(c_str); } Using the above, I got the error: i:\C++\C++Code\FileOperations\Form1.h(101): error C2230: ''ToUnmanagedString'': a member function of a managed class cannot return a non-managed class orstruct ''std::basic_string<_Elem,_Traits,_Ax>'' unless it is an aggregatewith[_Elem=wchar_t,_Traits=std::char_traits<wchar_t>,_Ax=std::allocator<wchar_t>] What does that mean? 这篇关于强制价值bool(业绩警告)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-21 23:14