相关疑难解决方法(0)

iostream和bits/stdc++.h有什么区别?我们什么时候需要使用它们?

我对 iostream 和 bits/stdc++.h 之间的差异感到困惑?在竞争性编程中可以使用bits/stdc++.h吗?或者有什么后果吗?

iostream header-files libstdc++

8
推荐指数
1
解决办法
1万
查看次数

与最大尺寸相关的数组和向量之间的差异?

当我在我的Devcpp编译器中运行此代码时 - >

#include<bits/stdc++.h>
using namespace std;
int main()
{
    vector<int> vec;
    for(int i=0;i<100000000;i++)
    vec.push_back(i);
}
Run Code Online (Sandbox Code Playgroud)

它甚至可以在运行时工作.但是当我跑 - >

#include<bits/stdc++.h>
using namespace std;
int arr[1000000000];
int main()
{
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

它给了我链接错误.

只要空间是必需的,arr和vec都需要相同的空间.那么为什么vec代码在运行时运行得很好但是arr代码甚至都没有编译.

c++ arrays vector

7
推荐指数
1
解决办法
210
查看次数

是否存在最长递增子序列的自上而下动态规划解决方案?

我想知道如何使用自上而下动态规划找到数组的 LIS。是否存在一种这样的解决方案?你能给我提供使用自顶向下动态规划查找数组 LIS 的伪代码吗?我无法在互联网上找到一个。他们都使用自下而上。

algorithm pseudocode dynamic-programming

7
推荐指数
2
解决办法
3902
查看次数

仅包含一个#include-expression一次包含多个头文件吗?

语法是否有可能一次包含多个标头的表达式,而无需为每个新文件编写“ #include”表达式?

例如,例如:

#include <stdio.h>, <stdlib.h>, <curses.h>, <string.h>  /* Dummy-Expression 1. */

OR

#include <stdio.h> <stdlib.h> <curses.h> <string.h>     /* Dummy-Expression 2. */

Run Code Online (Sandbox Code Playgroud)

问题是针对C AND C ++的。

c c++ syntax include header-files

7
推荐指数
3
解决办法
192
查看次数

#include &lt;Windows.h&gt; 是不好的做法吗?

我认为人们普遍认为这#include <bits/stdc++.h>是不好的做法,部分原因是它解析并包含每个标准标头,这几乎总是不必要的(它也是不可移植的,但这超出了我的观点)。当联合这更糟糕using namespace std;,因为现在你有一吨的通用名称的命名空间,喜欢next

然而,这似乎#include <Windows.h>主要被认为是可以的(我见过的大多数 Win32 程序都使用它),即使它在概念上与#include <bits/stdc++.h>+的组合做同样的事情using namespace std;

根据维基百科

windows.h是 C 和 C++ 编程语言的 Windows 特定头文件,其中包含 Windows API 中所有函数的声明、Windows 程序员使用的所有常用宏以及各种函数使用的所有数据类型和子系统。它定义了大量可在 C 中使用的 Windows 特定函数。

为什么会这样?是否不可能包含我们使用的特定标题而不包含<Windows.h>

c++ winapi

7
推荐指数
1
解决办法
2万
查看次数

为什么C++中有些字符无法编辑?

我正在尝试strcat用 C++ 编写自己的函数,但它有一些问题。
\n我的输入是两个字符c和,我的函数将返回一个指向与 相连的a字符的字符指针。ca

\n

例如,
\n输入:\'abc\' \'xyz\'
\n预期输出:\'xyzabc\'
\n我的函数的输出:\'xyza@\xe2\x96\xb2\xe2\x88\xa9\'

\n

我的函数返回一些与我的输入不同的特殊字符。

\n

我调试了我的函数并发现:

\n
    \n
  • 当 时i=0destination[3]= source[0]=\'a\'
  • \n
  • 但当i=1, destination[8]= source[1]=\'b\'
  • \n
  • i=2, destination[9]= source[2]=\'c\'
  • \n
  • 最后,destination[10]=\'\\0\'
  • \n
\n
#include<iostream>\n#include<string.h>\nusing namespace std;\n\nchar* mystrcat ( char * destination, const char *source){\n    for (int i=0; i<strlen(source); i++) {\n        destination[strlen(destination)+i] …
Run Code Online (Sandbox Code Playgroud)

c++ string strcat

7
推荐指数
1
解决办法
204
查看次数

如何从浮点数中得到精确的小数部分作为整数?

关于浮点数的十进制和整数提取以及某些特定小数点的输出,有很多问题和答案.但没有人能解决我的问题.如果有人能帮助我解决我的问题,请

我实际上是试图从浮点数中提取精确的小数部分.我试过这个:

float f=254.73;

int integer = (int)f;
float fractional = f-integer;

printf ("The fractional part is: %f", fractional);
Run Code Online (Sandbox Code Playgroud)

但输出为:0.729996.出于这个原因,当我这样做时:

float f=254.73;

int integer = (int)f;
float fractional = f-integer;
int fractional_part_in_integer = ((int)(f*100)%100);

printf ("The value is: %d", fractional_part_in_integer);
Run Code Online (Sandbox Code Playgroud)

它给了我72作为输出.但是,我想从给定的数字254.73中精确地提取73.我已经知道%.2fprintf()函数期间如何使用打印最多两个十进制数字.但在我的代码中,我现在不想打印这个数字.我有一些计算,其中小数部分为整数形式,即73.所以,我的问题是如何从254.73中提取小数部分,以便我可以得到精确的73作为整数来进行更多的计算?

希望,我能让每个人都理解.

c floating-point

6
推荐指数
2
解决办法
7818
查看次数

“std_lib_facilities.h”显示错误

我正在使用 Codeblocks 17.12 并且已经将编译器设置设置为 C++11 标准。我正在学习 Bjarne Stroustrup 的书“编程 - 使用 C++ 的原则和实践”。在他的书中,他要求包括“std_lib_facilities.h”。我从他的网站复制它并保存在“Mingw”文件夹的“include”文件夹中。之后,我开始制作一个简单的程序:

#include<iostream>
#include "std_lib_facilities.h"
main()
{
    std::cout<<"Hello world";
}
Run Code Online (Sandbox Code Playgroud)

但是编译器显示以下错误和警告:

 warning: This file includes at least one deprecated or antiquated header which may be removed without further notice at a future date.  
 Please use a non-deprecated interface with equivalent functionality instead. 
 For a listing of replacement headers and interfaces, consult the file backward_warning.h. To disable this warning use -Wno-deprecated. [-Wcpp]

 error: template-id 'do_get<>' for 'String > 
   std::__cxx11::messages<char>::do_get(std::messages_base::catalog, int, …
Run Code Online (Sandbox Code Playgroud)

c++ header

6
推荐指数
2
解决办法
4979
查看次数

C++ 找出所有基数,使得这些基数中的 P 以 Q 的十进制表示结尾

给定两个十进制数 P 和 Q。找出所有碱基,使得这些碱基中的 P 以 Q 的十进制表示结尾。

#include <bits/stdc++.h>

using namespace std;

void convert10tob(int N, int b)
{
     if (N == 0)
        return;
     int x = N % b;
     N /= b;
     if (x < 0)
        N += 1;
     convert10tob(N, b);
     cout<< x < 0 ? x + (b * -1) : x;
     return;
}

int countDigit(long long n) 
{ 
    if (n == 0) 
        return 0; 
    return 1 + countDigit(n / 10); 
} 

int main()
{
    long …
Run Code Online (Sandbox Code Playgroud)

c++ number-systems

6
推荐指数
1
解决办法
386
查看次数

为什么我无法在 GCC 13.x 版本中使用 #pragma GCC target(...) 声明字符串类型变量

我刚刚将 GCC 编译器版本从 11.4 更新到 13.1。我发现以下代码曾经在我的旧 GCC 11.4 上运行,但不再在 GCC 13.1 上运行。

#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")

#include <iostream>

int main() {
    std::string s = "Hello World!";
    std::cout << s << std::endl;
}
Run Code Online (Sandbox Code Playgroud)

这是编译器消息:

====================[ Build | run | Debug ]=====================================
"C:\Program Files\JetBrains\CLion 2023.3.2\bin\cmake\win\x64\bin\cmake.exe" --build C:\Users\zyk\CLionProjects\run\cmake-build-debug --target run -j 18
[1/2] Building CXX object CMakeFiles/run.dir/main.cpp.obj
FAILED: CMakeFiles/run.dir/main.cpp.obj 
C:\PROGRA~1\JETBRA~1\CLION2~1.2\bin\mingw\bin\G__~1.EXE   -g -fdiagnostics-color=always -MD -MT CMakeFiles/run.dir/main.cpp.obj -MF CMakeFiles\run.dir\main.cpp.obj.d -o CMakeFiles/run.dir/main.cpp.obj -c C:/Users/zyk/CLionProjects/run/main.cpp
In file included from C:/Program Files/JetBrains/CLion 2023.3.2/bin/mingw/lib/gcc/x86_64-w64-mingw32/13.1.0/include/c++/string:43,
                 from C:/Program Files/JetBrains/CLion …
Run Code Online (Sandbox Code Playgroud)

c++ gcc g++

6
推荐指数
1
解决办法
365
查看次数