如何将数字转换为字符号码?

发布于 2025-01-22 12:20:54 字数 439 浏览 0 评论 0原文

问题是下一个,生成一个新字符串, 1。在firt的地方:名称的firt信 2。第二名:名称的第三个字母 3。在thitd的地方:名字的最后一个字母 4。第四位:角色的lenght int main(){

char cad1[10]={};
char cad2[4]={};
int  n ; 

cout<<"Ingresa un nombre de 4 o mas letras : " ;
cin.getline(cad1,10,'\n') ;

n =  strlen(cad1) ;
    
cad2[0] = cad1[0] ;
cad2[1] = cad1[2] ;
cad2[2] = cad1[n-1] ;
cad2[3] ??

cout<<cad2;
cout<<endl ;
system("PAUSE") ; return 0 ; 

}

The problem is the next, generate a new string,
1. In the firt place : the firts letter of the name
2. In the second place : the third letter of the name
3. In the thitd place : The last letter of the name
4. In the fourth place : the lenght of the character
int main(){

char cad1[10]={};
char cad2[4]={};
int  n ; 

cout<<"Ingresa un nombre de 4 o mas letras : " ;
cin.getline(cad1,10,'\n') ;

n =  strlen(cad1) ;
    
cad2[0] = cad1[0] ;
cad2[1] = cad1[2] ;
cad2[2] = cad1[n-1] ;
cad2[3] ??

cout<<cad2;
cout<<endl ;
system("PAUSE") ; return 0 ; 

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

生活了然无味 2025-01-29 12:20:54

欢迎来到堆栈溢出!如果我正确理解了您的问题,则需要将键入的名称长度保存在最后一个字符上。如果是这样,那就做:

cad2[3] = n + '0';

Welcome to Stack Overflow! If I understood your question correctly, you need to save the typed name length on the last char. If that's the case, just do:

cad2[3] = n + '0';
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文