标签: visual-c++

常数如何表示?

我想知道变量是否被声明为volatile常量,是否可以使用i/o或任何外设进行更改?例如:volatile const int input = 0; 还有这样的变量可以存储在内存中吗?

c c++ visual-studio-2010 visual-c++

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

由继承的类C++重写的纯虚函数

可以通过具有常量纯虚函数的继承类覆盖纯虚函数(即末尾= 0的函数)并仍然被调用吗?

#include <stdio.h>

struct cBaseClass {
    virtual void VirtualFunction () = 0;
};

struct cInheritedClass : cBaseClass {
    virtual void VirtualFunction () const {
        printf ("I'm a constant virtual function that"
                " overrided a pure virtual function!\n");
        }
    }
};

int main() {
    cBaseClass *Foo = new cInheritedClass;
    Foo->VirtualFunction ();
}
Run Code Online (Sandbox Code Playgroud)

最后一行应该导致调用cInheritedClass :: VirtualFunction,而不是cBaseClass :: VirtualFunction.我希望常量函数只是一个编译器指令,以确保类中的任何内容都不会被写入并且不会影响继承.我在我的关卡类中使用它来处理一些碰撞例程,在这里指定函数是否可以基于每个对象/类修改类是很好的.

c++ inheritance visual-c++ c++11

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

结果这个程序错了?

我写了这个程序,我希望它打印输出'10'.但它正在打印15.为什么要这样做?

#include "stdafx.h"
#include"iostream"
#include<conio.h>
using namespace std;
void f(int a, int b){
    b=a+a;
}
int main(){
    int a = 5, b = 15;
    f(a,b);
    cout << b;
    _getch();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ visual-c++

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

函数调用中的参数太少

我想void getInput在主要范围内调用该函数。但是当我这样做时,它告诉我:

函数调用中的参数太少。

我该如何解决?

第一个void函数将打印练习。然后在下一个称为的void函数中调用它getInput。之后,我只想在main()函数中调用它。

#include <iostream>;
#include <string>;

using namespace std;

void Exercices()
{
    double speed;
    int minutes;

    cout << "walking: ";
    cin >> speed >> minutes;
    cout << "running: ";
    cin >> speed >> minutes;
    cout << "cycling: ";
    cin >> speed >> minutes;
}

void getInput(string username)
{
    double weight, goal;
    string walking, running, cycling;

    cout << "Please enter your name: ";
    cin >> username;
    cout << "Welcome " << username …
Run Code Online (Sandbox Code Playgroud)

c++ visual-c++

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

任何人都可以提供如何使用Windows ShutdownBlockReasonCreate的示例

谁能提供一个简单明了的例子ShutdownBlockReasonCreate?我一直试图通过MSDN页面弄清楚它,但我不理解它,而且我已经厌倦了每次尝试测试它时都不能关闭我的电脑而且它不起作用.如果有人熟悉并且可以提供一个非常棒的简洁示例!

这是我到目前为止,但我做'

#include <Windows.h>
#include <iostream>
std::wstring s2ws(const std::string& s)
{
    int len;
    int slength = (int)s.length() + 1;
    len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0); 
    wchar_t* buf = new wchar_t[len];
    MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len);
    std::wstring r(buf);
    delete[] buf;
    return r;
}

int main(int argc, char* argv[])
{
    if (ShutdownBlockReasonCreate(GetForegroundWindow(), s2ws("TEST").c_str()) != 0)
        std::cout << "Success" << std::endl;
    else
        std::cout << "Failure" << std::endl;

    while (1) 
    {
        Sleep(1000);
        std::cout << "Testing..." << std::endl;
    }
}
Run Code Online (Sandbox Code Playgroud)

c++ winapi visual-c++

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

C++数学问题和5/4*pi vs 5*pi/4

#define M_PI acos(-1.0)

int main()
{
    double z1 = sin(M_PI / 2 + 3 * x) / (1 - sin(3 * x - M_PI));
    double z2 = 1 / tan(5 * M_PI / 4 + 3 * x / 2);  // line 14
    double z3 = 1 / tan(5 / 4 * M_PI + 3 * x / 2);  // line 15

    printf("%lf, %lf, %lf, z1, z2, z3);
}
Run Code Online (Sandbox Code Playgroud)

因此,正如您在14行和15行中看到的,我们有非常相似的表达式.那么为什么我们得到不同的结果呢?

c c++ math visual-studio visual-c++

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

Windows 7的错误C++

我有一个问题:我很喜欢编译,点击BUILD en然后点击BUILD之后我得到了这个

Error 1 error C3859: virtual memory range for PCH exceeded; please recompile with a command line option of '-Zm176' or greater

Error 2 error C1076: compiler limit : internal heap limit reached; use /Zm to specify a higher limit

Error 3 error C3859: virtual memory range for PCH exceeded; please recompile with a command line option of '-Zm197' or greater

Picto的错误

PS.我会用/ Zm200到2000年尝试一切都没有用

c++ visual-c++

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

在 C++ 中从 CString 中删除“\”

如何\从 CString 中删除此字符?

例如:我有这个内容的字符串“这是\一个字符串”

如何\从我的字符串中删除?

非常感谢。

c++ mfc visual-c++

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

使用fscanf从文件读取数据后程序崩溃

我编写了一个简单的程序来读取文本文件的内容,然后用cl.exe(visual studio编译器)编译它.程序编译,当我运行它时,它正常启动,当它超过读取和打印数据时,它会残酷地崩溃......这是代码:

#include <iostream> 
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <fstream>
#include <string>


int main (int argc, char *argv[]) 
{
char filename[256];
char d1[9]; 
char d2[8];

if (argc > 1) //lecture de l'argument
strcpy(filename, argv[1]);
    else {
        printf("Usage: read_file");
        return 0;
    }

FILE *f = fopen(filename, "r");
if (f == NULL) {
  printf("Cannot find file \'%s\'\n", filename);
  return 0;
}

printf("file opened\n");

rewind(f);
fscanf(f, "%s %s", d1, d2);

printf("%s %s",d1,d2);
fclose(f);

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

当我用gcc编译它时它工作得很好.问题是,我需要使用visual studio编译器运行...

c++ visual-c++

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