为什么我的讲师写的所有C文件都以#开头?
我正在阅读一些C课程笔记,每个 C程序源文件都以程序#第一行的单个文件开头.
然后有空格,然后是其他东西后跟main函数.
是什么原因#?
(现在这是不合时宜的,我不能真的问这个小伙子.)
这是一个例子(在结束时有一个额外的行#)
#
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我一直在尝试在之前使用过的各种文件上运行Docker构建,现在这些文件已经不再有效了.
一旦Docker文件包含任何要安装软件的行,它就会失败并显示一条消息,说明找不到该软件包.
RUN apt-get -y install supervisor nodejs npm
Run Code Online (Sandbox Code Playgroud)
日志中出现的常见消息是
Could not resolve 'archive.ubuntu.com'
Run Code Online (Sandbox Code Playgroud)
知道为什么任何软件都不会安装?
我如何计算 Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch 中的字母?
print(len('Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch'))
Run Code Online (Sandbox Code Playgroud)
说 58
好吧,如果有那么容易,我就不会问你了,现在是吗?!
维基百科说(https://en.wikipedia.org/wiki/Llanfairpwllgwyngyll#Placename_and_toponymy)
名称的长格式是英国最长的地名之一,也是世界上最长的地名之一,有 58 个字符(51 个“字母”,因为“ch”和“ll”是二合字母,在威尔士语)。
所以我想数一数并得到答案 51。
对。
print(len(['Ll','a','n','f','a','i','r','p','w','ll','g','w','y','n','g','y','ll','g','o','g','e','r','y','ch','w','y','r','n','d','r','o','b','w','ll','ll','a','n','t','y','s','i','l','i','o','g','o','g','o','g','o','ch']))
51
Run Code Online (Sandbox Code Playgroud)
是的,但那是作弊,显然我想使用这个词作为输入,而不是列表。
维基百科也说威尔士语的有向图是ch, dd, ff, ng, ll, ph, rh, th
https://en.wikipedia.org/wiki/Welsh_orthography#Digraphs
所以我们走了。让我们把长度加起来,然后去掉重复计算。
word='Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch'
count=len(word)
print('starting with count of',count)
for index in range(len(word)-1):
substring=word[index]+word[index+1]
if substring.lower() in ['ch','dd','ff','ng','ll','ph','rh','th']:
print('taking off double counting of',substring)
count=count-1
print(count)
Run Code Online (Sandbox Code Playgroud)
这让我走到这一步
starting with count of 58
taking off double counting of Ll
taking off double counting of ll
taking off double counting of ng
taking off …Run Code Online (Sandbox Code Playgroud) 我正在使用编译器资源管理器,在使用类似这样的东西时,我偶然发现了三元运算符的一个有趣行为:
std::string get_string(bool b)
{
return b ? "Hello" : "Stack-overflow";
}
Run Code Online (Sandbox Code Playgroud)
编译器为此生成的代码(clang trunk,带 -O3)是这样的:
get_string[abi:cxx11](bool): # @get_string[abi:cxx11](bool)
push r15
push r14
push rbx
mov rbx, rdi
mov ecx, offset .L.str
mov eax, offset .L.str.1
test esi, esi
cmovne rax, rcx
add rdi, 16 #< Why is the compiler storing the length of the string
mov qword ptr [rbx], rdi
xor sil, 1
movzx ecx, sil
lea r15, [rcx + 8*rcx]
lea r14, [rcx + 8*rcx]
add r14, 5 #< …Run Code Online (Sandbox Code Playgroud) 我已经定义了一个结构,它有一个构造函数:
struct MyStruct
{
MyStruct(const int value)
: value(value)
{
}
int value;
};
Run Code Online (Sandbox Code Playgroud)
和以下对象:
int main()
{
MyStruct a (true);
MyStruct b {true};
}
Run Code Online (Sandbox Code Playgroud)
但是我没有收到任何编译错误,无论是MVS2015还是Xcode 7.3.1.
bool数据,但一段时间后,代码改变,bool变得int和介绍了几个错误.)我知道Python中的类通常使用camelCase.
如果文件只包含类,那么包含该类的文件也是camelCase也是常规约定吗?
例如,是否应该将类className存储在?className.py而不是class_name.py?
在C++中,您可以将许多内容声明为constexpr:变量,函数(包括成员函数和运算符),构造函数,以及自C++ 1z以来的if语句和lambda表达式.但是,声明析构函数会 constexpr导致错误:
struct X {
constexpr ~X() = default; // error: a destructor cannot be 'constexpr'
};
Run Code Online (Sandbox Code Playgroud)
我的问题:
constexpr?constexpr吗?~X() = default;),它会自动constexpr吗?当我在我个人的C和C++项目工作,我通常把file.h与file.cpp在同一目录下,然后file.cpp可以参考file.h与#include "file.h"指导.
但是,通常会找到库和其他类型的项目(如linux内核和freeRTOS),其中所有.h文件都放在include/目录中,而.cpp文件保留在另一个目录中.在那些项目中,.h文件也包括在内,#include "file.h"而不是#include "include/file.h"我希望的.
我对这一切有一些疑问:
.h文件内include/包含#include "file.h"代替#include "include/file.h"?我知道真正的技巧是在一些Makefile中,但是这样做是否真的更好而不是明确(在代码中)我们想要包含的文件实际上在include/目录中?我需要定义一些仅由一个类使用的常量字符串.看起来我有三个选择:
将字符串直接嵌入到使用它们的位置.
将它们定义为类的私有静态常量成员:
//A.h
class A {
private:
static const std::string f1;
static const std::string f2;
static const std::string f3;
};
//A.cpp
const std::string f1 = "filename1";
const std::string f2 = "filename2";
const std::string f3 = "filename3";
//strings are used in this file
Run Code Online (Sandbox Code Playgroud)在cpp文件中的匿名命名空间中定义它们:
//A.cpp
namespace {
const std::string f1 = "filename1";
const std::string f2 = "filename2";
const std::string f3 = "filename3";
}
//strings are used in this file
Run Code Online (Sandbox Code Playgroud)鉴于这些选项,您会推荐哪一个?为什么?谢谢.
我有一个Sqlite数据库,我想在其中选择TIMESTAMP列中的值在某个特定日期之前的行.我认为这很简单,但我无法完成.我试过这个:
SELECT * FROM logged_event WHERE logged_event.CREATED_AT < '2010-05-28 16:20:55'
Run Code Online (Sandbox Code Playgroud)
和日期函数一样,它有各种变化.我已经阅读了http://sqlite.org/lang_datefunc.html和http://www.sqlite.org/datatypes.html,我希望该列是一个数字类型,并且比较将在unix时间戳值.显然不是.有谁可以提供帮助?如果重要的话,我在Sqlite Expert Personal中尝试这个.
编辑:
这是类型表描述:
CREATE TABLE [logged_event]
(
[id] INTEGER NOT NULL PRIMARY KEY,
[created_at] TIMESTAMP,
[name] VARCHAR(64),
[data] VARCHAR(512)
);
Run Code Online (Sandbox Code Playgroud)
并且测试数据:
INSERT INTO table VALUES(1,'2010-05-28T15:36:56+0200','test','test');
INSERT INTO table VALUES(2,'2010-05-28T16:20:49+0200','test','test');
INSERT INTO table VALUES(3,'2010-05-28T16:20:51+0200','test','test');
INSERT INTO table VALUES(4,'2010-05-28T16:20:52+0200','test','test');
INSERT INTO table VALUES(5,'2010-05-28T16:20:53+0200','test','test');
INSERT INTO table VALUES(6,'2010-05-28T16:20:55+0200','test','test');
INSERT INTO table VALUES(7,'2010-05-28T16:20:57+0200','test','test');
Run Code Online (Sandbox Code Playgroud)