小编Shr*_*han的帖子

无法从'const int'转换为'int&'

我正在尝试执行以下代码:

#include <iostream>
using namespace std;

class A
{
    int x;
public:
    A(int i = 25) { x = i; }
    int &f() const { return x; }
};

int main()
{
    A a(15);
    cout << a.f();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

它创建一个名为的对象a,其x成员的值设置为15.但是,当我尝试调用该函数返回该值时,我收到一个错误.为什么会这样?

c++

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

解码SHA256密码

我使用下面的代码编码我的密码,如何使用它将其解码为正确的密码 C#

public static string EncodePassword(string password)
{
    var provider = new SHA256CryptoServiceProvider();
    var encoding = new UnicodeEncoding();
    return Convert.ToBase64String(provider.ComputeHash(encoding.GetBytes(password)));
}
Run Code Online (Sandbox Code Playgroud)

c#

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

为什么我们总是必须在C编程中使用fgetc命令而不是fscanf,它们执行相同的操作但打印出奇怪的结果?

在C编程中,每当我使用它fgetc(file)来读取所有字符,直到它的文件结束它.但是当我使用类似的fscanf(file, "%c")功能时,它会打印出奇怪的字符.码:

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

int main() {
    char c;
    FILE * file = fopen("D\\filename.txt", "r");
    while (c != EOF) {
        fscanf(file, "%c", &c);
        printf("%c", c);
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

但是,当我使用fgetc而不是fscanf,它的工作原理.并打印出文件中存在的每个字符.

任何人都可以回答为什么会这样吗?

c file-io scanf fgetc

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

错误:类型'double*'和'double'到二进制'operator /'的操作数无效

我有我的程序,我正在使用g ++编译器.

#include <iostream>
#include <math.h>
using namespace std;

double getCal(double *par);

int main() {
    double final_price;
    double discount;
    discount = 12;

    final_price = getCal(&discount);
    cout << "final price for you is" << final_price << endl;

    return 0;
}

double getCal(double *par) {
    double original_price;
    double r;

    cout << " enter the price" << endl;
    cin >> original_price;

    r= (par/100.00);
    return original_price - (original_price*r);
}
Run Code Online (Sandbox Code Playgroud)

我已经检查了cmath的参考但是我没有注意到会替换我的操作符的除法功能.标准杆和100.00都是双打.我应该改变什么?

c++

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

标签 统计

c++ ×2

c ×1

c# ×1

fgetc ×1

file-io ×1

scanf ×1