是否有一种方法可以通过原型制作更改类型的INT来键入char

Is there a way to change type int to type char by prototyping?

本文关键字:类型 INT char 原型制作 可以通过 方法 一种 是否      更新时间:2023-10-16

我正在制作一个项目。这是单独文件中的函数声明。

void PrintLines(int characterValue, int characterCount, int lineCount)

当我在主文件中原型时,我会使用:

void PrintLines(char characterValue, int characterCount, int lineCount);

这不会编译。我可以使用任何方法在不更改第一个INT类型的情况下将其输入主要方法(在其他文件中?

中)

我认为我必须输入演员。只需要弄清楚如何。

基本上,代码必须为

 void PrintLines(int characterValue, int characterCount, int lineCount)

用于文件1和

 void PrintLines(char characterValue, int characterCount, int lineCount);

用于主。我可能需要将ascii转换为char ...

您可以像这样过载函数,但是两个函数具有不同的签名,即在链接过程中会失败。我不确定您要实现的目标,但可能会委派它:

void PrintLines(char cv, int cc, int lc) {
    PrintLines(int(cv), cc, lc);
}

如果要传递char而不是int作为第一个参数,则只需这样做即可。示例:

int x, y;
char c;
// ...
PrintLines(c, x, y);

char可以隐式地施放于C 中的int。如果您喜欢:

,也可以对int进行手册。
PrintLines(static_cast<int>(c), x, y);

,所以我发现了它。

cout&lt;&lt;(char)tramevalue;

在带有函数的文件中。

我的A获得了65