可能重复:
GOTO被认为是无害的
GOTO仍然被认为是有害的?
有没有合理的理由goto在c ++程序中使用?我认识的每个人都说goto的定义是你编写错误的东西,我同意这一点,因为我找不到任何使用goto的理由
我有一些其他代码得到的这两个功能
def ROR(x, n):
mask = (2L**n) - 1
mask_bits = x & mask
return (x >> n) | (mask_bits << (32 - n))
def ROL(x, n):
return ROR(x, 32 - n)
Run Code Online (Sandbox Code Playgroud)
我想在程序中使用它们,需要16位旋转.但是,还有其他功能需要32位旋转,所以我想将32保留在等式中,所以我得到:
def ROR(x, n, bits = 32):
mask = (2L**n) - 1
mask_bits = x & mask
return (x >> n) | (mask_bits << (bits - n))
def ROL(x, n, bits = 32):
return ROR(x, bits - n)
Run Code Online (Sandbox Code Playgroud)
然而,当我测试这个问题时,答案出错了.然而,当代码是正确的时,值出现了
def ROR(x, n):
mask = (2L**n) - 1
mask_bits …Run Code Online (Sandbox Code Playgroud) 什么值通常用作错误值<container>.end()?即时通过一个简单的线性搜索std::list<int>,我想知道搜索没有出现在列表中的位置
谁能解释为什么Codeblocks会给我这些错误?:
error: ISO C++ forbids declaration of 'cout' with no type
error: invalid use of '::'
error: expected ';' before '<<' token
error: '<<x>>' cannot appear in a constant-expression // <<x>> is many different variable names
Run Code Online (Sandbox Code Playgroud)
我的代码简单如下:
#include <iostream>
#include "myclass.h"
int main(){
std::string data;
std::string e;
e = myclass().run(data);
std::cout << e << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
世界上发生了什么?
编辑:是的,我确实有iostream.抱歉没有提前把它放在那里
出于某种原因,mod我正在创建的值变为0,keygen尽管在制作时以及在运行keygen之后是正确的.我不明白为什么.有谁能告诉我?
class RC5{
private:
uint64_t w, r, b;
uint128_t mod;
std::string mode;
std::vector <uint64_t> S;
public:
RC5(std::string KEY, std::string MODE, uint64_t W = 32, uint64_t R = 12, uint64_t B = 16){
uint128_t mod = 1;
mod <<= W;
mode = MODE;
w = W;
r = R;
b = B;
std::cout << mod << std::endl; // 1 << 32
keygen(KEY);
std::cout << mod << std::endl; // 1 << 32
}
void keygen(std::string key){
std::cout << …Run Code Online (Sandbox Code Playgroud) 一系列bool还"优化",就像vector<bool>是?我想制作真或假的数组,但我也不希望有些问题vector<bool>出现在数组中,例如访问速度慢
有什么理由Dev C++不让我这么做file.open(file_name_variable)吗?我不明白为什么它不会让我打开任何东西,而是一个硬编码的名字,比如file.open("abc.txt")如何解决这个问题?不要使用Dev C++?
这基本上就是我所拥有的:
int open_file(string file_name){
ifstream file;
file.open(file_name);
if (!file.is_open()){
return 0;
}
return 1;
}
Run Code Online (Sandbox Code Playgroud) 访问网页并下载其内容的最基本方法是什么?我希望得到的网页只有文字,其中大部分是在表格中.
是否有一个std库(就像urllib在python中一样)?
为什么这段代码没有给我正确的大数值?它是否与我使用大于32位的数字有关?如果是这样,我如何让我的函数接受任何位大小的值?我只是重载功能吗?这似乎有点浪费空间
std::string makehex(unsigned int value, unsigned int size = 2){
std::string out;
while (value > 0){
out = h[value % 16] + out;
value /= 16;
}
while (out.size() < size)
out = "0" + out;
return out;
}
Run Code Online (Sandbox Code Playgroud)
编辑:用法:
std::string value = makehex(30, 5);
std::cout << value; // 0001e
Run Code Online (Sandbox Code Playgroud) 我在我的程序中得到一个轻微的数学错误,这导致其余部分出现问题,我不明白为什么会发生这种情况.在这部分类中,我没有为内置类型重载运算符(我希望).如果我这样做,请告诉我在哪里
此函数用于计算存储数字所需的最少位数,该数字存储在deque <uint8_t> value一个值中,因此0x123456将存储为{0x12,0x34,0x56},输出将存储为integer.bits()应该是21
// all types here are standard, so i dont know whats going on
unsigned int bits(){
unsigned int out = value.size() << 3;
std::cout << out << " " << value.size() << " " << (value.size() << 3) << std::endl;
uint8_t top = 128;
while (!(value.front() & top)){
out--;
top >>= 1;
}
return out;
}
Run Code Online (Sandbox Code Playgroud)
然而,这部分正在cout发挥作用
8 1 8
16 2 16
...
and finally,
18 3 18
Run Code Online (Sandbox Code Playgroud)
我在网上发现了一堆java文件,并且有一个功能出现在所有地方,但我找不到谷歌上的定义:compex.无论我如何使用符号来制作compex重要的搜索词,谷歌都会继续把我送到复杂的地方.它似乎无法从任何地方导入.所有我设法找出它是需要2个单个整数作为输入.
我不是一个java程序员.我只想弄清楚代码意味着什么
/*
* PermSortAlgorithm.java
* Patrick Morin takes no responsibility for anything. So there.
*
*/
/**
* A PermSort Demonstration algorithm. The PermSort algorithm is due
* to Patrick Morin <http:www.scs.carleton.ca/~morin>. The algorithm
* works by trying every permutation until it finds one that's
* sorted. That's right, there are n! permutations and it takes O(n)
* time to test each one, yielding an O(nn!) algorithm. No hate mail
* please.
*
* @author …Run Code Online (Sandbox Code Playgroud) 当printf("%s/%s\n", str1, str2);打印出字符串而sprintf(str3, "%s/%s", str1, str2);导致程序崩溃时,我可能忽略了一些简单的事情吗?
这只发生在我在VirtualBox上运行的Ubuntu(最新版本)上.在Windows(主机)上,两条线路都没有任何问题.
如果需要更多背景信息,请告诉我.我希望我错过了一些愚蠢的事情,那两条线路绰绰有余.
为什么在for循环中更改参数会导致程序崩溃?它对c ++来说太动态了吗?
for(unsigned int x = 0; x < mystring.size(); x++)
mystring = mystring.substr(0, mystring.size());
Run Code Online (Sandbox Code Playgroud)
当我改变我的真实代码来执行此操作(mystring.size()> 0)时,我的程序仍然崩溃
编辑:
好.你们是对的,由于mystring值的变化,代码没有崩溃.但是,这段代码很简单,我没看到错误来自哪里:
template <class Algorithm>
class ECB{ // Electronic codebook
private:
Algorithm algo;
uint8_t blocksize;
public:
ECB(Algorithm instance, std::string = "")
: algo(instance) {
blocksize = algo.blocksize() >> 3;
}
std::string encrypt(std::string data){
data = pkcs5(data, blocksize);
return data;
}
std::string decrypt(std::string data){
return remove_padding(data);
}
};
Run Code Online (Sandbox Code Playgroud)
请不要链接我到网站教我如何使用ECB.它不像它的硬.但是,这段代码很烦人