我想提取出现在 linux bash 脚本中间的数字:
APPLES_STR="We have 123 apples."
NUM=?????
Run Code Online (Sandbox Code Playgroud)
在C中我会做类似的事情:
int num;
const char *str = "We have 123 apples."
sscanf(str, "We have %d apples.", &num);
Run Code Online (Sandbox Code Playgroud)
我如何在 linux bash 中做到这一点?
我想渲染一个控件,该控件将出现在右侧,位于另一个占容器宽度 100% 的控件的顶部。
我想要的示例(带按钮):
z-index我尝试通过为小按钮的属性设置较高的值来实现此目的。但这不起作用。
我的尝试:
.mydiv {
display: flex;
flex-direction: row;
}Run Code Online (Sandbox Code Playgroud)
<div class="mydiv">
<button style="width:100%; height:30px;">big button</button>
<button style="width:80px; height:20px; z-index:99;">smallbutton</button>
</div>Run Code Online (Sandbox Code Playgroud)
不过我得到这个:
知道如何使用 Flexbox 来实现这一点吗position:absolute?如果可能的话?
我有一个头文件及其cpp文件(Error.h,Error.cpp).cpp文件对预处理程序指令执行检查,但始终失败.
Error.h:
/*
Optional macros:
AE_EXIT_AT_ERROR
AE_CONSOLE_WRITE_AT_ERROR
*/
#pragma once
extern void aeError(const char *str, int code=1);
extern void aeAssert(bool b, const char *failStr = "assertion failed");
Run Code Online (Sandbox Code Playgroud)
Error.cpp:
#include "Error.h"
#include <stdexcept>
#ifdef AE_CONSOLE_WRITE_AT_ERROR
#include <iostream>
#endif
void aeError(const char *str, int code)
{
#ifdef AE_CONSOLE_WRITE_AT_ERROR
std::cout << str << std::endl;
#endif
throw std::runtime_error(str);
#ifdef AE_EXIT_AT_ERROR
std::exit(code);
#endif
}
void aeAssert(bool b, const char *failStr)
{
if(!b)
aeError(failStr);
}
Run Code Online (Sandbox Code Playgroud)
main.cpp中:
//define both macros:
#define AE_CONSOLE_WRITE_AT_ERROR
#define AE_EXIT_AT_ERROR
#include "Error.h"
//rest …Run Code Online (Sandbox Code Playgroud) 我读了这个,我想不出X::_x在文件初始化之前将使用的场景X.cpp(假设编译器对待X.h并且X.cpp一个接一个)
有人可以向我解释这种情况会怎样吗?
如何计算封装其他两个球体的最小球体?
每个球体在 3d 空间中都有一个中心点和一个半径。
编辑:
这是我的代码。我正在尝试实现 merge() 函数,但我不知道如何实现。
#include <gl\glm\glm.hpp>
class Sphere
{
public:
Sphere();
Sphere(const glm::vec3 &point, float radius);
void set(const glm::vec3 &point, float radius);
void reset();
bool isReset() const;
const glm::vec3& getCenter() const { return _point; }
float radius() const { return _radius; }
void merge(const Sphere &other);
bool operator==(const Sphere &other) const {
return (_point == other._point && _radius == other._radius);
}
bool operator!=(const Sphere &other) const {
return !operator==(other);
}
private:
glm::vec3 _point;
float _radius;
};
Run Code Online (Sandbox Code Playgroud)