我有一个叫做的新功能removeInelligibleCharsFromTargetName.
void removeInelligibleCharsFromTargetName(string *targetName)
{
for(int i = 0; i < targetName->length(); i++)
{
for(int j = 0; j < ineligibleChars.length(); j++)
{
if(targetName[i] == ineligibleChars[j])
targetName[i] = '_';
}
}
}
Run Code Online (Sandbox Code Playgroud)
问题是当我在if循环中尝试比较时,我得到以下错误:
错误C2678:binary'==':找不到运算符,它接受类型为'std :: string'的左手操作数(或者没有可接受的转换)32> c:\ program files\microsoft sdks\windows\v6. 0a\include\guiddef.h(192):尝试匹配参数列表'(std :: string,char)时可能是'int operator ==(const GUID&,const GUID&)'
但是把那个完全相同的嵌套循环放回到我调用的地方而不是调用它可以正常工作的函数.
有人可以告诉我,它不会在函数中工作但在函数外工作正常.毫无疑问,这是一个指针,但我不知道是什么.
我正在读一本C++书.该程序试图制作一个对象矢量.这是我不明白的部分
class X {
public:
X();
X(int m) {
temp = x;
}
int temp;
X &operator =(int z) {
temp = z;
return *this;
}
private :
// Some functions here
}
Run Code Online (Sandbox Code Playgroud)
上面的线是什么意思?这是某种超载吗?那怎么样?
只是想知道是否存在不使用const_cast的缺点虽然传递char*并简单地将其类型转换为(char*)或两者基本上是同一个?
#include <iostream>
#include<conio.h>
using namespace std;
void print(char * str)
{
cout << str << endl;
}
int main ()
{
const char * c = "sample text";
// print( const_cast<char *> (c) ); // This one is advantageous or the below one
print((char *) (c) ); // Does the above one and this are same?
getch();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
是否存在使用print((char *) (c) );过度 print( const_cast<char *> (c) ); 或基本两者相同的缺点?
#include <iostream>
#include <Windows.h>
#include <process.h>
//#include "windowstate.cpp"
//DWORD WINAPI MyThreadFunction( LPVOID lpParam );
using namespace std;
int Zeit;
unsigned int __stdcall wfshutdown() {
Sleep(Zeit*60000);
system("shutdown -s -t 2");
return 0;
}
void shutdown() {
cout << "When I should shut down your PC(in minutes)" << endl;
cin >> Zeit;
if(Zeit==0) {
return;
}
// windowstate(0);
HANDLE hThread;
DWORD threadID;
hThread = (HANDLE)_beginthreadex( NULL, 0, &wfshutdown, NULL, 0, &threadID );
}
Run Code Online (Sandbox Code Playgroud)
我无法运行该程序.我收到此错误,我不明白:
错误1错误C2664:'_ beginthreadex':无法将参数3从'unsigned int(__stdcall*)(void)'转换为'unsigned int(__stdcall*)(void*)'32
我在网上搜索了一个多小时未成功找到解决方案,因此我非常希望你能提供帮助.
例如需要这个文本来写一个文件:
This is some simple text "it's quote", test test
我writeFile :: FilePath -> String -> IO ()用来写文件,但是当我尝试在文件中写这个字符串时,在文件中我看到:
This is some simple text \"it\'s quote\", test test
如何删除\符号,我只需要在我的文本文件中"没有\".
谢谢.
我编码下面的代码.我已经在我的程序中使用它,它似乎工作.无论如何,我在问它是否正确.
int SendMessageWMSIZE(HWND hwnd) {
RECT rc;
GetClientRect(hwnd,&rc);
int lParam_my;
short low=rc.right-rc.left; // LOWORD
short high=rc.bottom-rc.top; // HIWORD
lParam_my=(high<<16)|low; // construct an int 32 from two int 16
SendMessage(hwnd, WM_SIZE, 0, lParam_my);
return lParam_my;
}
Run Code Online (Sandbox Code Playgroud)
我不是要用"int"改变"short"(我可以将32 int改为16,但将16改为16)?
如果我使用"短"或"整数"而不是短裤,它为什么会起作用?
我有两个问题.
我知道可以在结构中声明类对象.但从设计的角度来看,这样做是否道德?
在我的场景中,我有一个包含大量成员元素的结构,我也希望包含一个类对象.我有另一个问题.如果我memset()整个结构,类句柄也被重置.所以,我检查没有类对象的结构的其余部分的大小,并在我调用memset()时减去它,以解决这个问题.(请注意,我在这里使用STL类'队列'.我不能在对象上使用sizeof()运算符,因为它没有重载.)
但这完全是一种不可接受的方式吗?你能为这个问题提出一些解决方案吗?
看下面的代码:
public class Foo {
private static Foo sigleton=new Foo();
private static int count1;
private static int count2=0;
private Foo (){
count1++;
count2++;
}
public static Foo getInstance(){
return sigleton;
}
public static void main(String[] args) {
//Foo f= Foo.getInstance(); // case 1
//Foo f= new Foo(); // case 2
System.out.println(f.count1);
System.out.println(f.count2);
}
}
Run Code Online (Sandbox Code Playgroud)
对于每次运行,取消注释main方法中的一行.
为什么案例1和2的输出不同?
我有以下算法(基于SHA-1哈希函数实现).它产生"abc"的哈希值.结果是未签名的char*摘要.
#define BYTES "abce"
SHA1* sha1 = new SHA1();
sha1->addBytes( BYTES, strlen( BYTES ) );
unsigned char* digest = sha1->getDigest();
Run Code Online (Sandbox Code Playgroud)
我想重新考虑结果摘要.我是按照以下方式做到这一点但不起作用.是否char* S定义了不同的东西#define BYTES "abce"?
char* S = reinterpret_cast<char*>(digest);
sha1 = new SHA1();
sha1->addBytes( S, strlen( S ) );
unsigned char* digest1 = sha1->getDigest();
Run Code Online (Sandbox Code Playgroud) 我必须显示一个计算出的数字,有时它很小,显示如下:
1.0E-8.
Run Code Online (Sandbox Code Playgroud)
我如何显示它像
0.00000001
Run Code Online (Sandbox Code Playgroud)