我想检查一个元素是否存在于特定的向量位置,比如i,然后像v [i]一样访问它.你能让我知道我该怎么办?
谢谢.
那么char上的操作是原子的吗?所以在线程AI中读取char T并在线程BI中写入相同的char T,这些标准操作是原子的吗?
char a;
#thread A
{
if(a & 0x01)
...
}
#thread B
{
a =0x01;
...
}
# ATOMIC?
Run Code Online (Sandbox Code Playgroud)
谢谢!
我正在努力消除SECURITY CODING产品中的违规行为.我的代码有很多sprintf,覆盖率工具建议我使用snprintf,但C++也有std::stringstream.用它std::stringstream代替是一个好主意snprintf
我编写了一个程序,通过对字母使用 switch 命令将十进制字符串转换为十六进制,但是如果我使用 char 程序不能正常工作!没有开关,我无法处理 9 以上的数字 .. 我希望你确实理解我,因为我的语言不是那么好。
所以这是我的程序
顺便说一句,如果把它int而不是char它工作正常,但它变成了11而不是B
#include <iostream>
using namespace std;
int main()
{
int n, i, c=0, t;
char a[50];
cout << "Enter a decmail number :\n";
cin >> n;
t = n;
for (i = 0; t > 0; i++)
{
if (a[i] % 16 > 9)
{
switch(a[i])
{
case 10 : a[i] = 'A'; break;
case 11 : a[i] = 'B'; break;
case 12 …Run Code Online (Sandbox Code Playgroud) 所以,我有一个std::list<std::string>,我问是否有一个功能或技巧随机化列表.
例:
first elem of the list : "Hello"
second elem of the list : "Stack"
third elem of the list : "Over"
fourth elem of the list : "Flow"
fifth elem of the list : "!!"
Run Code Online (Sandbox Code Playgroud)
我想要的是一个函数或技巧来获取这样的随机列表,例如:
first elem of the list : "Flow"
second elem of the list : "!!"
third elem of the list : "Hello"
fourth elem of the list : "Stack"
fifth elem of the list : "Over"
Run Code Online (Sandbox Code Playgroud)
我想你明白我的意思:)
我想要一种与二进制搜索类似的算法,其中我有一个数字n,比方说3,数组如下:
array[10] = {1,2,3,3,3,3,3,3,3,4,5,6}
Run Code Online (Sandbox Code Playgroud)
我希望算法返回,p = 2因为前3个出现在数组的第2位.
对于此算法,假设数组已经排序.
我知道如何使用二进制搜索,但我不知道如何使它成为n数组中的第一个而不是n它找到的第一个.
我一直在尝试使用这个c ++程序按字母顺序排序5个名称:
#include <iostream>
#include <cstring>
#include <conio.h>
using namespace std;
int main()
{
char names[5][100];
int x,y,z;
char exchange[100];
cout << "Enter five names...\n";
for(x=1;x<=5;x++)
{
cout << x << ". ";
cin >> names[x-1];
}
getch();
for(x=0;x<=5-2;x++)
{
for(y=0;y<=5-2;y++)
{
for(z=0;z<=99;z++)
{
if(int(names[y][z])>int(names[y+1][z]))
{
strcpy(exchange,names[y]);
strcpy(names[y],names[y+1]);
strcpy(names[y+1],exchange);
break;
}
}
}
}
for(x=0;x<=5-1;x++)
cout << names[x];
return 0;
}
Run Code Online (Sandbox Code Playgroud)
如果我分别进入厄尔,唐,克里斯,比尔和安迪,我得到这个:
AndyEarlDonChrisBill
Run Code Online (Sandbox Code Playgroud)
有人可以告诉我我的程序有什么问题吗?