小编mal*_*lea的帖子

C语言中的字符编码取决于什么?

C语言中的字符编码取决于什么?(操作系统?编译器?还是编辑器?)我不仅处理 ASCII 字符,还处理其他编码(例如 UTF-8)的字符。

我们如何检查 C 中当前的字符编码?

c gcc character-encoding

5
推荐指数
1
解决办法
3220
查看次数

我们不能管理 std::map<string,ofstream> 吗?

我尝试创建输出计时结果并从预定义字符串调用任何 ofstream:

\n\n
#include <cstring>                                                                                                                  \n#include <map>\n#include <fstream>\n\nusing namespace std;\n\nint main(void) {\n    map<string,ofstream> Map;\n    ofstream ofs("test_output");\n    string st="test";\n    Map[st] = ofs;\n    return 0;\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

我收到以下错误;我该如何修复它?

\n\n
#include <cstring>                                                                                                                  \n#include <map>\n#include <fstream>\n\nusing namespace std;\n\nint main(void) {\n    map<string,ofstream> Map;\n    ofstream ofs("test_output");\n    string st="test";\n    Map[st] = ofs;\n    return 0;\n}\n
Run Code Online (Sandbox Code Playgroud)\n

ofstream c++11

4
推荐指数
1
解决办法
807
查看次数

数组变量在哪里用C语言存储?

#include <stdio.h>

int main(){
    int array[] = {1,2,3};
    printf("L00: array[0]=%d \n",array[0]);
    printf("L01: array[1]=%d \n",array[1]);
    printf("L02: array[2]=%d \n",array[2]);
    printf("L03: &array[0]=%p \n",&array[0]);
    printf("L04: &array[1]=%p \n",&array[1]);
    printf("L05: &array[2]=%p \n",&array[2]);
    printf("L06: array=%p \n",array);
    printf("L07: &array=%p \n",&array);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

在这个程序中,L03,L06,L07和显示(&array,array,和&array[0],分别地)相同的存储器地址.

所以我很好奇"阵列"作为RAM中变量的位置.

如果RAM中没有"数组"的位置,它在哪里?

c arrays pointers

4
推荐指数
4
解决办法
217
查看次数

使用std :: chrono :: high_resolution_clock时,“ operator =“不匹配

当我在下面编译此timer.hpp头文件时,编译器说:

错误:“ operator =”不匹配(操作数类型为“ std :: chrono :: _ V2 :: system_clock :: time_point {aka std :: chrono :: time_point>>}”和“ std :: __ success_type>> ::”输入{aka std :: chrono :: duration>}')end = std :: chrono :: high_resolution_clock :: now()-开始;

我猜开始和结束的变量类型是错误的。什么是正确的类型?我要用std::chrono::high_resolution_clock

#include <chrono>

namespace timer{
static std::chrono::system_clock::time_point start, end;

void initTime(){
    start = std::chrono::high_resolution_clock::now();
}


void endTime(){
    end = std::chrono::high_resolution_clock::now() - start;
}

}
Run Code Online (Sandbox Code Playgroud)

应该将timer.hpp与某些主文件一起使用。
通过timer::initTime()在要测量的某个函数之前调用,然后timer::endTime()在该函数之后调用,我将获得计时结果(此处省略了持续时间的吸气剂)。

c++ timer c++11 c++-chrono

3
推荐指数
1
解决办法
1606
查看次数

我应该如何使用唯一指针在C ++ 11时,析构函数是私有的?

我管理其析构函数是私有的,因为对象必须被分配到堆的类。

让我们假设这个类为A。

 std::unique_ptr<A> a(new A());
Run Code Online (Sandbox Code Playgroud)

当这是一个范围时,析构函数被调用。

然而,的unique_ptr的默认行为是调用“公共析构函数”。

在这种情况下,我应该怎么做,而不会使析构函数公开?

unique-ptr c++11

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

printf是否在C中使用堆栈帧?

假设我们创建了一个用户函数void func().func的堆栈帧是在函数调用时分配的,只要在main等其他函数中调用它.

printf一样吗?是否 printf的也消耗堆栈帧?

c stack printf

0
推荐指数
1
解决办法
683
查看次数