标签: codeblocks

帮助在C++中使用PCRE

这是我第一次尝试构建一个C++应用程序,所以我有点迷茫.我看了一些例子,但我还是不知道出了什么问题.

#include <iostream>
#include <stdio.h>
#include <windows.h>
#include <pcrecpp.h>
#include <string>
#include <cstring>

using namespace std;

int main()
{
    char title[256];
    char url[256];
    string song, diff;
    HWND hwnd = FindWindow("WindowsForms10.Window.8.app.0.33c0d9d", NULL);
    GetWindowTextA(hwnd, title, 255);
    pcrecpp::RE re("^osu!  - (.*) \\[(.*)\\] \\[[|-]{21}\\]$");
    re.FullMatch(title, &song, &diff);
    sprintf(url, "xfire:game_stats?game=%s&%s=%s&%s=%s", "osu", "Playing", song.c_str(), "Difficulty", diff.c_str());
    ShellExecute(NULL, NULL, url, NULL, NULL, SW_SHOWDEFAULT);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

当我尝试编译时,我得到以下编译器错误

obj\Debug\main.o||In function 'main':| C:\Users\Zeffy\Desktop\osu-gamestats\main.cpp|18|undefined reference to '_imp___ZN7pcrecpp2RE6no_argE'| C:\Users\Zeffy\Desktop\osu-gamestats\main.cpp|18|undefined reference to '_imp___ZN7pcrecpp2RE6no_argE'| C:\Users\Zeffy\Desktop\osu-gamestats\main.cpp|18|undefined reference to '_imp___ZN7pcrecpp2RE6no_argE'| C:\Users\Zeffy\Desktop\osu-gamestats\main.cpp|18|undefined reference to '_imp___ZN7pcrecpp2RE6no_argE'| C:\Users\Zeffy\Desktop\osu-gamestats\main.cpp|18|undefined …

c++ windows pcre g++ codeblocks

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

模板参数1无效(Code :: Blocks Win Vista) - 我不使用模板

我的学校项目有些麻烦.

我有一节课:

#include "Group.h"
#include <vector>
#include <string>
using namespace std;

class User{
    private :
        string username;
        vector<Group*> groups;
        void show() {
            for(int i=0; i<groups.size(); i++)
                cout << groups[i]->getName() << "\n";
        }
        string getUsername(){return username;}

};
Run Code Online (Sandbox Code Playgroud)

#include "User.h"
#include <vector>
#include <string>
using namespace std;

class Group{
    private :
        string name;
        string getName(){return name;};
        User *f;
        vector<User*> m;
        void show(){
            for(int i=0; i<m.size(); i++)
                cout << m[i]->getUsername() << "\n";
        }
};
Run Code Online (Sandbox Code Playgroud)

当我尝试编译它时,它给了我错误:

E:\Group.h|31|error: ISO C++ forbids declaration of 'User' …
Run Code Online (Sandbox Code Playgroud)

c++ codeblocks

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

由于EOF字符,导致此程序提前离开for循环的条件是什么?

继续看看这篇文章的底部是否有实际问题

我可能试图将这些非常简单的事情理解得太多,但在我弄清楚这一点之前我无法继续.

在阅读K&R 1.9字符阵列时,您会遇到一个示例程序,它接受输入并确定哪条线最长,然后重新打印它.

为了理解该程序的getline功能,我稍微修改了它以在其进展过程中打印一些信息.现在我找到了一些输入,一旦我理解,应该大大增强我对getchar()的理解.


另外,当我尝试从库中读取源代码时,我完全不知所措.例如,我试图追捕getchar()并最终盯着#endifstddef.h的300号线某处的18号塔楼目瞪口呆.我将通过在不久的将来停止在stdio.h中寻求功能来避免这种麻烦.图书馆很难找到一些东西,这是正常的吗?该函数不应该作为可读源存在,还是我只是希望得到它?


为了方便起见,我将继续并从K&R发布整个修改过的程序:

#include <stdio.h>
#define MAXLINE 5   /* maximum input line length */

int getline(char line[], int maxline);
void copy(char to[], char from[]);

/* print the longest input line */
main()
{
    int len;            /* current line length */
    int max;            /* maximum length seen so far */
    char line[MAXLINE];    /* current input line */
    char longest[MAXLINE]; /* longest line saved here */
    max = 0;
    while ((len = getline(line, MAXLINE)) > 0) …
Run Code Online (Sandbox Code Playgroud)

c codeblocks kernighan-and-ritchie

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

代码块电源功能在c中不起作用

我正在使用代码块来学习c.我的代码是

#include<stdio.h>
#include<math.h>
int main()
{
  int x;
  x = pow(5,2);
  printf("%d", x);
}

Output is 25
Run Code Online (Sandbox Code Playgroud)

当我使用此代码时

#include<stdio.h>
#include<math.h>
int main()
{
  int x,i,j;
  printf("please enter first value");
  scanf("%d", &i);//5
  printf("please enter second value");//2
  scanf("%d", &j);
  x = pow(i,j);
  printf("%d", x);
}

Output is 24
Run Code Online (Sandbox Code Playgroud)

这有什么不对?我只是使用扫描功能获取价值,并以同样的方式使用pow功能.

c c++ codeblocks

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

如何调试c ++运行时错误

我使用MinGW作为编译器,使用CodeBlocks作为IDE.当出现运行时错误时,程序只是停止工作而没有任何错误消息.是否有可能获得传统的错误消息,如错误类型和发生的位置?

c++ runtime-error mingw codeblocks

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

致命错误:QtGui/QApplication:没有这样的文件或目录|

首先,是的,我确实彻底搜索了几十个相似的名字帖子,我的解决方案要么不存在,要么对我对该主题的有限知识不明显.

我相当精通C++,经常使用它,但我确实刚刚发现了QT,并决定对它进行重击.错误是非常基本的,我认为这意味着我做了一些非常基本的错误.

我在用什么:

  1. 最新版本的CodeBlocks
  2. QT的最新版本
  3. 本主题的一段示例代码:( 使用QtGui显示QImage).
  4. 代码块安装在这里:C:\ Program Files(x86)\ CodeBlocks
  5. MinGW:C:\ MinGW\bin
  6. QT:C:\ Qt\4.8.5\bin

这是我完整的环境路径:

C:\Program Files (x86)\SSH Communications Security\SSH Secure Shell; C:\Qt\4.8.5\bin
Run Code Online (Sandbox Code Playgroud)

从我引用的帖子中,听起来这是一个完整且有效的程序(我用自己的图像替换了图像),这进一步强化了我的观点,即我以一种小而深刻的方式进行了愚弄.

参考代码:

#include <QtGui/QApplication>
#include <QLabel>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QImage myImage;
    myImage.load("test.png");

    QLabel myLabel;
    myLabel.setPixmap(QPixmap::fromImage(myImage));

    myLabel.show();

    return a.exec();
}
Run Code Online (Sandbox Code Playgroud)

CodeBlocks构建并运行完整的错误日志:

C:\Users\Josh\Dropbox\Code\Cards\qtTest_loadololo.cpp|1|fatal error: QtGui/QApplication: No such file or directory|
||===

 Build finished: 1 errors, 0 warnings (0 minutes, 4 seconds) ===|
Run Code Online (Sandbox Code Playgroud)

完整的构建日志:

\Dropbox\Code\Cards\qtTest_loadololo.o
C:\Users\Josh\Dropbox\Code\Cards\qtTest_loadololo.cpp:1:30: fatal error: QtGui/QApplication: No such file …
Run Code Online (Sandbox Code Playgroud)

c++ qt install codeblocks

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

使用ruby阻止内插

我正在编写一个简单的程序,要求用户输入数组并吐出数组及其平均值.真的很容易,我没有任何问题.

最后我想出了:(在这个例子中,我只使用随机数组而不是用户输入的代码)

array = [1,2,3]
sum = array.inject(:+)
average = sum.to_f/array.length
puts "The numbers you entered in the array were: #{array.join(" ")}"
puts "The average of those numbers are: #{average}"
Run Code Online (Sandbox Code Playgroud)

输出是预期的,并给我:

The numbers you entered in the array were: 1 2 3
The averages of those numbers are: 2.0
Run Code Online (Sandbox Code Playgroud)

然而,当我第一次尝试编码时,我试图通过简单的分配进行实际光滑,我尝试在插值中进行插值.我使用了这段代码:

对于上面代码中的第四行,我使用了:

puts "The numbers you entered in the array were: #{array.each{|num| print "#{num} "}}" 
Run Code Online (Sandbox Code Playgroud)

输出:

1 2 3 The numbers you entered in the array were: [1, 2, 3]
Run Code Online (Sandbox Code Playgroud)

所以我认为在插值内部的块内进行插值可能存在问题.然后我运行以下代码来测试内插中的一个块. …

ruby arrays codeblocks string-interpolation

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

无论输入如何,strcmp始终为true

所以我目前正在学习C编程,为大学期开学做准备.有点像"抬腿"的事情.无论如何,我正在做一些比较字符串和使用字符串复制函数在字符串数组中放置新值的练习,但我得到一些我真的无法解释的意外行为.无论我输入什么,它总是显示字符串比较检查的肯定结果,我无法确定我出错的地方.如果有人愿意帮助我,我将不胜感激!

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    char tVar1[10];
    char tVar2[10];

    printf("Enter your first test variable: \n");
    scanf("%c", &tVar1);

    strcpy(tVar2, "yes");

    if(strcmp(tVar1, "yes") == 0)
        {
            printf("It would probably be more effective if you used two different variables.");
        }
    else
        {
            printf("Nope, just the same amount of effectiveness.");
        }

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

c codeblocks

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

使用C++中的用户输入变量声明数组大小.在不同的IDE中有不同的结果?

我需要创建一个程序,用户输入所需的数组大小,然后C++代码创建它,然后允许数据输入.

这适用于Code Blocks IDE,但不适用于Visual Studio Community 2015

当我在CodeBlocks版本13.12中放入以下代码时,它可以工作

#include<iostream>
using namespace std;

int main()
{
    int count;
    cout << "Making the Array" << endl;
    cout << "How many elements in the array " << endl;
    cin >> count;
    int flex_array[count];
    for (int i = 0; i < count; i = i + 1)
    {
        cout << "Enter the " << i << " term " << endl;
        cin >> flex_array[i];
    }

    for (int j = 0; j < count; j …
Run Code Online (Sandbox Code Playgroud)

c++ arrays vector codeblocks visual-studio-2015

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

在C++中使用蒙特卡罗方法找到π的问题

我有一个程序应该使用蒙特卡罗方法找到π的近似值,代码如下:

#include <iostream>
#include <cstdlib>
#include <cmath>

int main()
{
    double x=0, y=0, piEstimate=0, precision=0;
    int N;
    int nIn=0, nOut=0;
    std::cout << "Please enter the seed number." <<std::endl;
    std::cin >> N;
    for(int i=0;i<=N;i++){
        x=(double)rand()/(double)RAND_MAX;
        y=(double)rand()/(double)RAND_MAX;
        if(sqrt(x*x+y*y)>1){
            nOut++;
        }else if(sqrt(x*x+y*y)<1){
            nIn++;
        }
    }
    piEstimate=4*(nOut/nIn);
    std::cout<<"The estimate of pi with "<<N<<" seeds is "<<4.0*(nOut/nIn)<<"."<<std::endl;
    std::cout<<"Error percentage at "<<abs(100.0-piEstimate/3.1415926)<<"."<<std::endl;
}
Run Code Online (Sandbox Code Playgroud)

但是,这会产生以下输出,这似乎是不合理的: montecarloprogramoutput 这里有什么问题,为什么程序会为π生成这样不准确的数字?我假设我的逻辑在中间某处失败,但我无法弄清楚在哪里...运行Code :: Blocks 16,C++ 0X标准.

c++ algorithm codeblocks montecarlo

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