我想将一个随机数与一些字母数字字符交错,例如:HELLO与随机数25635→混合H2E5L6L3O5.我知道%1d控制间距,虽然我不知道如何在随机数之间插入文本或如何实现这一点.
码:
int main(void) {
int i;
srand(time(NULL));
for (i = 1; i <= 10; i++) {
printf("%1d", 0 + (rand() % 10));
if (i % 5 == 0) {
printf("\n");
}
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
顺便说一句 - 如果我的随机数发生器不是很好,我愿意接受建议 - 谢谢
我在 El Capitan 上,我通过 Xcode 创建了一个新项目,我选择了其中OS X -> Application -> Game (Language: Objective-C, Game Technology: Metal)
该项目最初编译并运行没有问题。
然后我将主视图控制器重命名GameViewController.m为GameViewController.mm使用 Objective-C++。当我现在构建时,我收到以下链接器错误:
体系结构 x86_64 的未定义符号:“_MTKMetalVertexDescriptorFromModelIO”,引用自:GameViewController.o 中的 -[GameViewController _loadAssets] “_OBJC_CLASS_$_MDLMesh”,引用自:GameViewController.o 中的 objc-class-ref “_OBJC_CLASS__$_MTKMesh”,引用自:objc GameViewController.o 中的 -class-ref “_OBJC_CLASS_$_MTKMeshBufferAllocator”,引用自:GameViewController.o 中的 objc-class-ref:未找到架构 x86_64 的符号
我尝试过将金属标头包裹进去extern "C" {},但这没有帮助。
我怎样才能让它构建?
我gobjc在 Ubuntu 16.04 中安装了 GNUStep 。我可以像这样编译 Objective-C 代码:
gcc codefile.m `gnustep-config --objc-flags` -lobjc -lgnustep-base -o codefile
Run Code Online (Sandbox Code Playgroud)
但我想在 GCC 中编译 Objective-C++ 代码。我该怎么做?
是否可以在 Objective-C++ 中创建具有指向 Objective-C 接口(在文件内.h)的指针的字段的类?
为了澄清一点,我创建了一个 Objective-C 接口:
// Our platform independent class
@interface LoggerDelegate : NSObject<SomeDelegate>
@end
Run Code Online (Sandbox Code Playgroud)
我可以在文件内创建它.mm并且它可以工作,但它适用于全局变量,并且不允许我更改其范围。所以我想在里面使用它Logger.h:
class Logger {
public:
private:
LoggerDelegate* _ptr; //<--- pointer to the Objective-C interface
};
Run Code Online (Sandbox Code Playgroud)
当我在里面定义我的界面时,Logger.mm它就可以工作了。但是是否可以将 Objective-C 和 C++.h文件内的 Objective-C++ 代码合并到一起?或者只能在.mm文件中进行?
我正在尝试在 iOS 上的 Tensorflow Lite 中使用 GPU 委托。我的模型的输入和输出为 OpenCV BGR 图像 ([258, 540, 3])。如何在 C++ tensorflow lite 解释器中设置输入和输出?我尝试使用此代码
int input = interpreter->inputs()[0];
float* out = interpreter->typed_tensor<float>(input);
NSData* slicedData = [self inputDataFromCvMat:slicedImage];
uint8_t* in = (uint8_t*) slicedData.bytes;
ProcessInputWithFloatModel(in, out, WIDTH, HEIGHT, CHANNELS);
Run Code Online (Sandbox Code Playgroud)
void ProcessInputWithFloatModel(uint8_t* input, float* buffer, int image_width, int image_height, int image_channels) {
for (int y = 0; y < wanted_input_height; ++y) {
float* out_row = buffer + (y * wanted_input_width * wanted_input_channels);
for (int x = 0; x < …Run Code Online (Sandbox Code Playgroud) 我有源样本包含.m和.c文件.
我想在我的目标c项目中使用这个示例.
我的问题是在这种情况下需要使用桥接头?
此项目也是在2011年创建的,其中包含[self release]会产生错误,因为它已经过时并且已弃用,我如何解决这些产生错误的旧函数,如"release"?
所以我有一个以下问题.我有一个类,它是另外两个类的子类,它们都有位置.就像在这个例子中:
struct A
{
float x, y;
std::string name;
void move(float x, float y)
{
this->x += x;
this->y += y;
}
};
struct B
{
float x, y;
int rows, columns;
void move(float x, float y)
{
this->x += x;
this->y += y;
}
};
struct C : public A, public B
{
void move(float x, float y)
{
this->x += x; //generates error: "C::x is ambiguous
this->y += y; //generates error: "C::y is ambiguous
}
};
Run Code Online (Sandbox Code Playgroud)
在代码的后面,我将C类称为A类和B类,当我得到这个位置时,我遇到了问题.我可以以某种方式"组合"两个类的位置变量吗?如果没有,我可以同时更改两个类的位置,或者我必须这样做:
void …Run Code Online (Sandbox Code Playgroud) 我如何在课堂外访问私有引导程序?我想修改该对象的参数。
我尝试使getter并通过引用返回向量,但是当我尝试更改主函数中vector包含的对象的参数时,不会保存vector的更改。
class Restaurant
{
std::vector <Waiter> waiters_vector_;
public:
inline std::vector<Waiter> &GetWaitersVector() { return waiters_vector_; }
void Restaurant::AddWaiter(Waiter tmp)
{
waiters_vector_.push_back(tmp);
}
Restaurant();
~Restaurant();
};
class Waiter
{
int current_group_id_=0;
public:
int GetCurrentGroupId()
{
return current_group_id_;
}
void SetCurrentGroupId(int tmp)
{
current_group_id_ = tmp;
}
Waiter();
~Waiter();
};
int main()
{
Restaurant restaurant1;
Waiter w1, w2, w3;
restaurant1.AddWaiter(w1);
restaurant1.AddWaiter(w2);
restaurant1.AddWaiter(w3);
for (Waiter element : restaurant1.GetWaitersVector())
{
element.SetCurrentGroupId(123);
}
for (Waiter element : restaurant1.GetWaitersVector())
{
std::cout << element.GetCurrentGroupId() << std::endl;
} …Run Code Online (Sandbox Code Playgroud) 我正在进行面向对象编程,我必须Box[10在C++语言中给10个不同的框(由10个元素数组表示)提供不同的名称(physBox1,physBox2 ..... physBox10).
for (G4int i=0; i<10; i++)
{
new G4PVPlacement(0, Box[i],"phyBox[i]");
}
Run Code Online (Sandbox Code Playgroud)
这G4PVPlacement是一个带有三个值的类 - 第二个值Box[i]表示10个框,并且physBox[i]是该框的名称.在这里我很困惑是否physBox[i]将被视为单个字符串,或者[i]根据"for循环"可以在0到9之间运行.