小编The*_*Cat的帖子

c ++ 11异步seg错误

我只是尝试使用GCC 4.7.2的一些新的C++ 11功能,但是当我去运行seg故障时.

$ ./a.out
Message from main.
terminate called after throwing an instance of 'std::system_error'
  what():  Unknown error -1
Aborted (core dumped)
Run Code Online (Sandbox Code Playgroud)

我编译了GCC的'beta'功能,关于c ++ 0x:

g++ -std=c++11 c11.cpp
Run Code Online (Sandbox Code Playgroud)

代码:

#include <future>
#include <iostream>

void called_from_async() {
  std::cout << "Async call" << std::endl;
}

int main() {
  //called_from_async launched in a separate thread if possible
  std::future<void> result( std::async(called_from_async));

  std::cout << "Message from main." << std::endl;

  //ensure that called_from_async is launched synchronously 
  //if it wasn't already launched
  result.get();

  return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ multithreading asynchronous c++11

13
推荐指数
1
解决办法
1474
查看次数

constexpr用指针初始化

我试图用指向int的指针初始化一个constexpr声明,这是一个const对象.我还尝试使用不是const类型的对象定义对象.

码:

#include <iostream>

int main()
{
constexpr int *np = nullptr; // np is a constant to int that points to null;
int j = 0;
constexpr int i = 42; // type of i is const int
constexpr const int *p = &i; // p is a constant pointer to the const int i;
constexpr int *p1 = &j; // p1 is a constant pointer to the int j; 
}
Run Code Online (Sandbox Code Playgroud)

g ++日志:

constexpr.cc:8:27: error: ‘& i’ is not …
Run Code Online (Sandbox Code Playgroud)

c++ pointers const constexpr

11
推荐指数
1
解决办法
4484
查看次数

如何在Linux中调用"cpuid"?

在为Windows编写新代码时,我偶然发现_cpuinfo()了Windows API.因为我主要处理Linux环境(GCC),所以我希望能够访问CPUInfo.

我尝试过以下方法:

#include <iostream>

int main()
{
  int a, b;

  for (a = 0; a < 5; a++)
  {
    __asm ( "mov %1, %%eax; "            // a into eax
          "cpuid;"
          "mov %%eax, %0;"             // eax into b
          :"=r"(b)                     // output
          :"r"(a)                      // input
          :"%eax","%ebx","%ecx","%edx" // clobbered register
         );
    std::cout << "The code " << a << " gives " << b << std::endl;
  }

  return 0;
}
Run Code Online (Sandbox Code Playgroud)

这使用组件,但我不想重新发明轮子.有没有其他方法可以在没有汇编的情况下实现CPUInfo?

编译器错误:

lewis@lewis-desktop:~/Desktop/prog$ g++ -Wall CPUInfo.cpp
CPUInfo.cpp: In function ‘int …
Run Code Online (Sandbox Code Playgroud)

c++ cpu assembly

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

未定义的对"GlewInit"的引用 - OpenGL

我在尝试生成可执行文件时遇到此错误,代码正确编译但是当我点击make命令时,我收到此错误消息:

gcc -c helloworld.c
lewis@lewis-desktop ~/Desktop/Dev/gl $ make
gcc -o hello-gl helloworld.o -L/usr/X11R6/lib -lGL -lglut -lGLEW -lm
helloworld.o: In function `Initialize':
helloworld.c:(.text+0x55): undefined reference to `GlewInit'
collect2: ld returned 1 exit status
make: *** [helloworld] Error 1
Run Code Online (Sandbox Code Playgroud)

我正在运行Linux Mint 13,我认为这与我的makefile有关,我不太了解它们所以我一起攻击了一个并在网上找到了一些代码:

GL_INCLUDE = /usr/X11R6/include
GL_LIB = /usr/X11R6/lib
GL_GLEW = /user/include

helloworld: helloworld.o
    gcc -o hello-gl $^ -L$(GL_LIB) -lGL -lglut -lGLEW -lm

.c.o:
    gcc -c -o $@ $< -I$(GL_INCLUDE)

clean:
    rm -f hello-gl hello-gl-dummy hello-gl.o util.o hello-gl-dummy.o
Run Code Online (Sandbox Code Playgroud)

我的代码:

#include <stdlib.h>
#include <stdio.h> …
Run Code Online (Sandbox Code Playgroud)

c linux opengl glut freeglut

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

机器如何解释二进制?

我只是想,机器如何解释二进制代码?我所理解的是你的代码变成了1和0,所以机器可以理解它们,但它们是如何做到的?它只是二进制翻译的普通文本吗?

compiler-construction binary cpu operating-system cpu-architecture

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

函数x的隐式声明

我很清楚函数原型,这个错误似乎是一个函数声明错误,这意味着我真的很困惑,为什么我看到这个警告,从而错误.

这几乎就像gcc完全忽略了我的函数原型.这是编译器错误吗?

为了简洁起见,我没有在单独的头文件中声明此函数,尽管它应该没有区别.

gcc输出:

$ gcc -Wall -std=c99 -pedantic primefactors.c
primefactors.c: In function ‘main’:
primefactors.c:8:5: warning: implicit declaration of function ‘largestprime’ [-Wimplicit-function-declaration]
primefactors.c: At top level:
primefactors.c:12:6: error: conflicting types for ‘largestprime’
primefactors.c:8:20: note: previous implicit declaration of ‘largestprime’ was here
Run Code Online (Sandbox Code Playgroud)

码:

#include <stdio.h>
#include <math.h>

long largetsprime(long);

int main()
{
    printf("%d\n", largestprime(600851475143));
    return 0;
}

long largestprime(long num)
{
    int highest;
    int mid = sqrt(num);
    for (int i = 2; i < mid; i++) {
        if (mid % i …
Run Code Online (Sandbox Code Playgroud)

c algorithm prime-factoring

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

Java中的感叹号是什么意思?

我想确认!=控制语句中布尔表达式之前的含义是否相反:

例如:

if (!networkConnected()) 
Run Code Online (Sandbox Code Playgroud)

这是否意味着"如果网络没有连接"?

java

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

向量下标无法添加元素

在使用子脚本操作符编写一些非常简洁的C++之后,我在程序中出现了一个小错误 - 没有输出.

我输入这个(Linux)

54 73 89 43 38 90
Run Code Online (Sandbox Code Playgroud)

然后点击Cntrl + D进行EOF.程序不输出任何内容并停止执行.

资源:

#include <iostream>
#include <string>
#include <vector>

using std::cin;
using std::vector;
using std::cout;
using std::endl;

int main() {
vector<unsigned> scores(11, 0); //11 buckets, all initially 0
unsigned grade;
while(cin >> grade) //read the grades
{
   if(grade <=100) //handles only valid inputs
  {
   ++scores[grade/10]; //increment counter for the current cluster
  }
 }
}
Run Code Online (Sandbox Code Playgroud)

我没有在VIM中更改我的设置,因此编码风格略有偏差.我无法想象有什么问题,while循环非常标准.它会读入成绩,直到找到流无效为止.然后我检查输入是否小于100(含).最后一段代码(它非常简洁)在向量中找到正确的元素来递增计数器.

我有一种感觉,它可能是我的输入导致程序无法输出.

编辑1:我添加了输出语句,我通过使用dereferencing a来做到这一点,它始终是一个引用.

#include <iostream>
#include <string>
#include <vector>

using std::cin;
using std::vector;
using …
Run Code Online (Sandbox Code Playgroud)

c++ vector cin subscript

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

尝试"最终"语句时出现语法错误

我已经提出了"最终"声明,但是我得到了语法错误,我对如何纠正它们一无所知,我已经尝试了所有方法,但无济于事.我的类得到两个编辑文本字段中的字符串,如果选中该复选框,则将两个字符串保存到文件中,以便稍后调用,然后,如果编辑文本中没有任何内容,则显示一个吐司.如果这是他们的第一次,他们的数据(用户并传递它保存),如果他们在通过检查文件之前完成此操作,它将通过意图转到另一个类.哦,对不起我的错误代码,我是一个新的Java程序员,我试图尽可能整洁.其次,如果有比我更好的编码方式,请随意更改,

谢谢.

标有^的错误.

码:

Button send;
    EditText user;
    EditText pass;
    CheckBox staySignedIn;
    FileOutputStream Fos;
    String a;
    String b;
    String string = a;
    String string2 = b;


    String FILENAME = "userandpass";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);
        send = (Button) findViewById(R.id.bLogIn);
        user = (EditText) findViewById(R.id.eTuser);
        pass = (EditText) findViewById(R.id.eTpassword);
        staySignedIn = (CheckBox) findViewById(R.id.Cbstay);
        send.setOnClickListener(this);

        File file = getBaseContext().getFileStreamPath(FILENAME);
        if (file.exists())
            ;
        Intent i = new Intent(LogIn.this, ChatService.class);
        startActivity(i); ^
    }


    public void onClick(View v) …
Run Code Online (Sandbox Code Playgroud)

java syntax android syntax-error

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

字符计数程序不输出任何东西?

很抱歉问这么简单的问题,我还在学习C并首先完成基础知识.

我正在创建一个字符计数程序但是当我执行程序并尝试输入"h"例如然后按回车键出现一个新行并且没有输出到该行?

码:

#include <stdio.h>

/* Copy input and count characters 2nd version */

main() {
    double cc;
    for(cc = 0; getchar() != EOF; ++cc);
    printf("%.0f\n", cc);
}
Run Code Online (Sandbox Code Playgroud)

c unix linux

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