Questions tagged «c++»

C ++是一种通用编程语言。它最初被设计为C的扩展,并且具有类似的语法,但是现在它是一种完全不同的语言。使用此标记可解决有关将要使用C ++编译器编译的代码的问题。对于与特定标准修订版[C ++ 11],[C ++ 14],[C ++ 17]或[C ++ 20]等相关的问题,请使用特定于版本的标记。

7
静态函数已声明但未在C ++中定义
使用C ++从以下代码中获取错误。 Main.cpp #include "file.h" int main() { int k = GetInteger(); return 0; } 文件.h static int GetInteger(); File.cpp #include "file.h" static int GetInteger() { return 1; } 我得到的错误: Error C2129: static function 'int GetInteger(void)' declared but not defined. 我已经读过著名的文章“在C和C ++中组织代码文件”,但不了解此代码有什么问题。


8
将64位整数中的压缩8位整数并行减1,SWAR不带硬件SIMD
如果我有一个64位整数,那么我会将其解释为具有8个元素的打包8位整数数组。我需要1在处理溢出时从每个压缩整数中减去常数,而一个元素的结果不会影响另一个元素的结果。 我现在有这段代码,它可以工作,但是我需要一个解决方案,它可以并行地对每个压缩的8位整数进行减法,并且不进行内存访问。在x86上,我可以使用类似的SIMD指令psubb,以并行方式减去打包的8位整数,但是我正在编码的平台不支持SIMD指令。(在这种情况下为RISC-V)。 因此,我正在尝试执行SWAR(寄存器中的SIMD)以手动取消a的字节之间的进位传播uint64_t,从而执行以下操作: uint64_t sub(uint64_t arg) { uint8_t* packed = (uint8_t*) &arg; for (size_t i = 0; i < sizeof(uint64_t); ++i) { packed[i] -= 1; } return arg; } 我认为您可以使用按位运算符来执行此操作,但我不确定。我正在寻找不使用SIMD指令的解决方案。我正在寻找一种可移植的C或C ++解决方案,或者只是其背后的理论,以便我可以实现自己的解决方案。
77 c++  c  bit-manipulation  simd  swar 


3
将C ++字符串拆分为多行(代码语法,不解析)
不要与如何分割明智的字符串混淆,例如: 在C ++中分割字符串? 关于如何在c ++中将字符串拆分为多行,我有些困惑。 这听起来像一个简单的问题,但请举以下示例: #include <iostream> #include <string> main() { //Gives error std::string my_val ="Hello world, this is an overly long string to have" + " on just one line"; std::cout << "My Val is : " << my_val << std::endl; //Gives error std::string my_val ="Hello world, this …

7
如何在C ++中创建一个简单的Qt控制台应用程序?
我试图创建一个简单的控制台应用程序来尝试Qt的XML解析器。我在VS2008中启动了一个项目,并获得了以下模板: int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); return a.exec(); } 由于我不需要事件处理,因此我想知道是否忽略创建QCoreApplication并运行事件循环是否会遇到麻烦。文档指出,在大多数情况下建议这样做。 但是出于好奇,我想知道如何使一些通用任务在事件循环上执行,然后终止应用程序。我无法用Google搜索相关示例。
77 c++  qt  console 


4
c ++ 11 regex比python慢
嗨,我想了解为什么下面的代码使用正则表达式进行拆分字符串拆分 #include<regex> #include<vector> #include<string> std::vector<std::string> split(const std::string &s){ static const std::regex rsplit(" +"); auto rit = std::sregex_token_iterator(s.begin(), s.end(), rsplit, -1); auto rend = std::sregex_token_iterator(); auto res = std::vector<std::string>(rit, rend); return res; } int main(){ for(auto i=0; i< 10000; ++i) split("a b c", " "); return 0; } 则慢于以下python代码 import re …

12
如何使用Qt创建暂停/等待功能?
我正在玩Qt,我想在两个命令之间创建一个简单的暂停。但是,它似乎不允许我使用Sleep(int mili);,也找不到任何明显的等待功能。 我基本上只是在制作一个控制台应用程序来测试一些类代码,这些类代码随后将包含在适当的Qt GUI中,因此,到目前为止,我无需担心破坏整个事件驱动的模型。
77 c++  qt  sleep  wait 

4
没有新的C ++对象
这是一个非常简单的问题,但是我好几年都没有正确地完成c ++的工作,所以对此我感到有些困惑。另外,在互联网上查找(而不是尝试)不是最简单的事情(至少对我而言)。 为什么不使用new关键字,它如何工作? 基本上,这是怎么回事? CPlayer newPlayer = CPlayer(position, attacker);
77 c++  new-operator 

9
'uint32_t'未命名类型
我正在尝试编译2007年编写的C ++软件包,但出现此错误: error: ‘uint32_t’ does not name a type 这在使用g ++ 4.5.2的64位Ubuntu中发生。使用g ++ 4.1.2在64位CentOS上可以很好地编译。 #include我是否缺少一个或编译器标志?或者,我应该使用typedef分配uint32_t给asize_t还是也许unsigned int?
77 c++  uint32-t  cstdint 

5
curl.h没有这样的文件或目录
我安装了curl这个命令(我使用Ubuntu): sudo apt-get install curl 当我使用测试简单程序时 g++ test.cpp #include <stdio.h> #include <curl/curl.h> int main(void) { CURL *curl; CURLcode res; curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, "http://example.com"); /* Perform the request, res will get the return code */ res = curl_easy_perform(curl); /* Check for errors */ if(res != CURLE_OK) fprintf(stderr, …
77 c++  curl 

6
警告-有符号和无符号整数表达式之间的比较
我目前正在通过Accelerated C ++工作在练习2-3中遇到了一个问题。 程序概述-程序基本上会命名,然后在星号的框架内显示问候语-即Hello!用*包围。 练习-在示例程序中,作者使用const int确定问候语和星号之间的填充(空白)。然后,作为练习的一部分,他们要求读者向用户输入有关其填充尺寸的信息。 这一切似乎很容易,我继续向用户询问两个整数(int),并存储它们,并更改程序以使用这些整数,并在编译时删除了作者使用的整数,尽管我得到了以下警告; 练习2-3.cpp:46:警告:有符号和无符号整数表达式之间的比较 经过一些研究,似乎是因为代码试图将上述整数(int)与a进行比较string::size_type,这很好。但是我想知道-这是否意味着我应该将整数之一更改为 unsigned int?显式声明我的整数是带符号的还是无符号的是否重要? cout << "Please enter the size of the frame between top and bottom you would like "; int padtopbottom; cin >> padtopbottom; cout << "Please enter size of the frame from each side you would like: "; unsigned int …


29
C ++-十进制到二进制转换
我写了一个“简单”(花了我30分钟)程序,将十进制数转换为二进制。我敢肯定,有很多简单的方法,所以你可以告诉我吗?这是代码: #include <iostream> #include <stdlib.h> using namespace std; int a1, a2, remainder; int tab = 0; int maxtab = 0; int table[0]; int main() { system("clear"); cout << "Enter a decimal number: "; cin >> a1; a2 = a1; //we need our number for later on so we save it …
77 c++  binary  decimal 

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.