小编Kei*_*son的帖子

">> 3"是什么意思?它是某种重定向吗?

我试图找出什么

 >> 3 
Run Code Online (Sandbox Code Playgroud)

在下面显示的代码中.是>>重定向,如果是,那么什么是3?有人可以帮忙吗?

#define BYTESIZE(bitsize)       ((bitsize + 7) >> 3)
Run Code Online (Sandbox Code Playgroud)

c bit-shift

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

将结果从线程转储到向量中是否安全?

我正在学习C++ 11的功能,并按照以下几行编写了一些代码

#include <vector>
#include <thread>
using std::thread;
using std::vector;

double Computation(int arg)
{
    // some long-running computation
    return 42.0;
}

double ConcurrentComputations()
{
    const int N = 8; // number of threads
    vector<thread> thr;
    vector<double> res(N);
    const int arg = 123456; // something or other
    // Kick off threads which dump their results into res
    for(int i=0; i<N; ++i)
        thr.push_back(thread ([&res, i, arg]()
                {  res[i] =  Computation(arg); } ));
    // Wait for them to finish and get results
    double …
Run Code Online (Sandbox Code Playgroud)

c++ multithreading c++11

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

在Linux环境中从另一个用C编写的文件调用用C编写的外部函数

我在调用我在 Linux 的 Pico 编辑器中编写的外部函数时遇到问题。程序应该调用外部函数,它们都是用 C 编写的。

#include????

void calcTax()
float calcfed()
float calcssi()
Run Code Online (Sandbox Code Playgroud)

// 存根程序

#include"FILE2"???or do I use"./FILE2"// not sure which to use here or what        extension     the file should have. .c or .h and if it is .h do I simply change the file     name to file.h?
#include<stdio.h>
#define ADDR(var) &var

extern void calctaxes()
int main()
{
}
Run Code Online (Sandbox Code Playgroud)

我正在使用 gcc 进行编译,但它不会编译。两个文件位于同一目录中并且具有 .c 扩展名

我是一名新学生,所以请耐心等待。

c

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

正则表达式为10或13位数

我试过这个,但在这种情况下,也允许使用11和12:

^[0-9]{10,13}$
Run Code Online (Sandbox Code Playgroud)

我只需要10或13.

regex

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

如何组合2个整数以获得1?

我搜索了这个,但我没有在C语言中找到这个问题的明确答案.

想象一下,我有一个int a = 123和另一个int b = 456.

如何组合它们才能获得combine(a, b) == 123456

c

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

如何在函数内使用cin?

我是c ++的新手,我正在尝试制作一个简单的基于文本的游戏.下面的代码应该欢迎用户加入游戏并询问用户是否想要开始游戏.我没有得到任何构建错误,但是当我运行它时,它显示的是一个空白屏幕.我究竟做错了什么?

代码如下:

string D1(string Original)
{
    cin >> Original;
    return Original;
}

int main ()
{
    string Decision1;
    cout << "Welcome to [game name]" << endl;
    cout << "Would you like to start the game?" << endl;
    cout << "Yes/No" << endl;
    string D1(Decision1);
    system("cls");
    if (Decision1 == "Yes")
    {
        cout << "this happens" << endl;
    }
    else if (Decision1 == "No")
    {
        cout << "that happens" << endl;
    }
}
Run Code Online (Sandbox Code Playgroud)

c++ function

0
推荐指数
2
解决办法
4963
查看次数

将int转换为字符串

str2是我需要追加str1的字符串,是我追加的字符串str2.在我追加到最后,str2我需要附加一个数字(int cnt)str2.所以我使用下面的代码,它出现在我的脑海中并且正在运行.这样的代码是不对的,因为我看到了 编译器对库的抱怨的使用string s = lexical_cast<string>(a);itoa (i,buffer,10);实现.

    string str2;
    string str1;
    int cnt;
    str2 += str1 ;
    str2 += char(cnt+48);//cnt converted to ASCII char and appended;
Run Code Online (Sandbox Code Playgroud)

c++ string int

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

错误:在'Hash_Flag'之前预期','或'...'

我有一个结构,定义为

typedef struct
{
  char* p_hash_start_position;
  size_t hash_capacity;

  //still a flag is needed since we might start from an empty container.
  Hash_Flag hash_status;

  char* p_start_position;
  char* p_current_position;
  size_t capacity;//tagged data capacity
} tagged_data_t;  
Run Code Online (Sandbox Code Playgroud)

枚举定义为

typedef enum Hash_Flag
{
    TD_HASH,
    TD_NO_HASH
} Hash_Flag;
Run Code Online (Sandbox Code Playgroud)

为什么我会收到以下错误?

error: expected ',' or '...' before 'Hash_Flag'
Run Code Online (Sandbox Code Playgroud)

c++ enums struct

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

Shell - 为什么内置的RANDOM函数返回1?

今天,我发现我的shell脚本偶尔会提前退出.检查代码后,我发现这是因为set -e我的shell脚本中有一个,我使用内置函数RANDOM生成一个随机数.

使用set -e,如果脚本中的任何命令返回非零,脚本将立即退出.所以我写了一段测试代码,如下所示:

set -u
#set -e

for (( i=0; i < 100; i++ ))
do
index=$(expr ${RANDOM} % 16)
echo "RANDOM return $? , index is $index"
done
Run Code Online (Sandbox Code Playgroud)

注意评论set -e,我这样做是为了显示100输出线,其中一些RANDOM return 1确实存在.例如,我得到这样的结果:

RANDOM return 0 , index is 2
RANDOM return 0 , index is 10
RANDOM return 1 , index is 0
RANDOM return 0 , index is 9
RANDOM return 0 , index is 5
RANDOM …
Run Code Online (Sandbox Code Playgroud)

bash shell

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

"git pull" runs out of memory

I tired to git pull, it suddenly comes out ..

Please let me know what I have to do

git pull
remote: Counting objects: 196, done.
remote: warning: suboptimal pack - out of memory
remote: fatal: Out of memory, malloc failed (tried to allocate 220610561 bytes)
error: git upload-pack: git-pack-objects died with error.
fatal: git upload-pack: aborting due to possible repository corruption on the remote side.
remote: aborting due to possible repository corruption on the remote side.
fatal: early EOF …
Run Code Online (Sandbox Code Playgroud)

git github

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

标签 统计

c++ ×4

c ×3

bash ×1

bit-shift ×1

c++11 ×1

enums ×1

function ×1

git ×1

github ×1

int ×1

multithreading ×1

regex ×1

shell ×1

string ×1

struct ×1