编译以下代码:
double getDouble()
{
double value = 2147483649.0;
return value;
}
int main()
{
printf("INT_MAX: %u\n", INT_MAX);
printf("UINT_MAX: %u\n", UINT_MAX);
printf("Double value: %f\n", getDouble());
printf("Direct cast value: %u\n", (unsigned int) getDouble());
double d = getDouble();
printf("Indirect cast value: %u\n", (unsigned int) d);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出 (MSVC x86):
INT_MAX: 2147483647
UINT_MAX: 4294967295
Double value: 2147483649.000000
Direct cast value: 2147483648
Indirect cast value: 2147483649
Run Code Online (Sandbox Code Playgroud)
输出 (MSVC x64):
INT_MAX: 2147483647
UINT_MAX: 4294967295
Double value: 2147483649.000000
Direct cast value: 2147483649
Indirect cast value: …Run Code Online (Sandbox Code Playgroud) C++ Primer 说字符和字符串文字可以转换为strings。
我尝试为 a 分配一个字符string:
std::string s;
s = 's';
Run Code Online (Sandbox Code Playgroud)
它没有给我任何错误。
但是,当我尝试将字符分配给 a vectorof strings 对象时:
std::vector<std::string> svec;
svec = {'a', 'b'};
Run Code Online (Sandbox Code Playgroud)
它给了我一个错误。为什么?
在以下代码中:
class Outer {
private:
void f_private(Outer::Inner in); // Wrong
public:
class Inner {};
void f_public(Outer::Inner in); // OK
};
Run Code Online (Sandbox Code Playgroud)
f_private()不能使用嵌套类Outer::Inner作为参数类型。但是在f_public().
有人可以向我解释这是基于什么规则,它有什么好处?
我不明白为什么下面的代码没有按预期工作:
#include <stdio.h>
int main() {
int i = 0, size = 9, oneOrZero[] = {1,1,1,1,1,1,1,1,0};
while (i < size && oneOrZero[i++]);
if (i == size) printf("All ones"); else printf("Has a zero");
}
Run Code Online (Sandbox Code Playgroud)
Terminal: All ones.
Run Code Online (Sandbox Code Playgroud)
当增加循环内的索引时,代码按预期运行:
#include <stdio.h>
int main() {
int i = 0, size = 9, oneOrZero[] = {1,1,1,1,1,1,1,1,0};
while (i < size && oneOrZero[i]) {i++;}
if (i == size) printf("All ones"); else printf("Has a zero");
}
Run Code Online (Sandbox Code Playgroud)
Terminal: Has a zero.
Run Code Online (Sandbox Code Playgroud)
有人可以解释这两者之间的区别吗?
我正在使用 ASP .NET Core 3.0 和 Angular 项目。我看到了这个新内容ApiAuthorizationDbContext,我想覆盖表名和用户 ID(到 int),但我无法做到。有谁知道诀窍吗?
这是用于覆盖表名称的上下文的类,但它创建AspNetUser和User表。为什么它不像往常一样创建一个?
public class ApplicationDbContext : ApiAuthorizationDbContext<AppUser>
{
public ApplicationDbContext(
DbContextOptions options,
IOptions<OperationalStoreOptions> operationalStoreOptions) : base(options, operationalStoreOptions)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<AppUser>(entity => { entity.ToTable(name: "User"); });
modelBuilder.Entity<AppRole>(entity => { entity.ToTable(name: "Role"); });
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的用户:
public class AppUser : IdentityUser
{
}
Run Code Online (Sandbox Code Playgroud)
通常我会用 覆盖主键,AppUser<int>但由于ApiAuthorizationDbContext.
有任何想法吗?
我刚刚发现 C 编译器有非常奇怪的行为。这是非常简单的代码。我在很多在线C编译器中尝试过,但结果总是一样的,这让我抓狂。
#include <stdio.h>
int main()
{
char Buffer[10] = "0123456789";
char ID[5] = "abcde";
printf("%s",ID);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
花点时间尝试预测函数的结果printf。如果你是像我一样的人,那么我认为最明显的解决方案是“abcde”,这是不正确的!但如果你以某种方式算出了“abcde0123456789”,那么你就在消耗电力来生活。
怎么、怎么可能?我只选择ID要打印的数组,那么为什么Buffer也用它打印呢?这没有道理。即使ID数组也不够大,无法容纳所有数据。我真的要失去理智了。
我的项目以前有工作通知,我无法追踪我发送的有效负载的任何更改。我已经参考了文档,但看不到我的有效负载有任何问题。我得到的确切错误是
请求包含无效参数
let payload = {
token : oUser.devicetoken,
data : {
referenceid : chatid,
referencetype : 'chat',
referencename : oSender.displayname,
receiverid : userid,
type : 'message',
notificationid : res,
title : title,
body : `${oSender.displayname} : ${body}`
},
android : {
priority : 'high'
},
apns : {
payload : {
aps : {
'content-available' : 1
}
},
headers : {
'apns-push-type' : 'background',
'apns-priority' : '5',
'apns-topic' : 'llc.attebyte.partyme'
}
}
};
Run Code Online (Sandbox Code Playgroud)
我当前的有效载荷:
在重新查看 Apple 文档的通知后,我注意到我应该使用content-available …
apple-push-notifications ios firebase react-native firebase-cloud-messaging
#include <compare>
#include <iostream>
int main()
{
auto comp1 = 1.1 <=> 2.2;
auto comp2 = -1 <=> 1;
std::cout << typeid(comp1).name()<<"\n"<<typeid(comp2).name();
}
Run Code Online (Sandbox Code Playgroud)
输出:
结构 std::partial_ordering
结构 std::strong_ordering
我知道如果操作数具有整数类型,则运算符将返回一个 prvalue 类型std::strong_ordering。我也知道操作数是否有浮点类型,运算符会产生类型的纯右值std::partial_ordering。
但是为什么我应该使用三向比较运算符而不是双向运算符(==, !=, <, <=, >, >=)?这对我有什么好处吗?
是否可以使用聚合初始化使指针aptr指向a同一成员struct?
struct S {
int a;
int* aptr;
};
int main() {
S s = {
.a = 3,
.aptr = &a //point aptr to a
};
return 0;
}
Run Code Online (Sandbox Code Playgroud)
问题是针对C和C++。
我很想知道为什么static_assert下面代码中的第二个不起作用。似乎即使数组c是对 的引用a,数组的大小也嵌入在类型中,因此它应该在编译时可用。
#include <array>
int main()
{
std::array<int,2> a = {1,2};
std::array<int,2> b = {2,3};
std::array<int,2>& c = a;
static_assert(a.size() == b.size(), "a.size==b.size"); // ok size of array is compile time constant
static_assert(c.size() == a.size(), "c.size==a.size"); // compiler error "static_assert expression is not an integral constant expression"
}
Run Code Online (Sandbox Code Playgroud)