我正在尝试执行以下代码:
#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#
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编程中,每当我使用它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,它的工作原理.并打印出文件中存在的每个字符.
任何人都可以回答为什么会这样吗?
我有我的程序,我正在使用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都是双打.我应该改变什么?