📄 strcatio.cpp
字号:
//这个程序在本书所带软盘中。文件名为STRCATIO.CPP
//这个程序利用输入/输出转向、字符串连接、数值到字符串的转换以及动态地址
//字节分配为输入的字符串加行号。
#include <iostream.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <conio.h>
void main(void)
{
char *line;
char text[81]; //定义数组
int line_num = 1;
cout << "加行号处理正在进行,请稍候..." << endl;
while (gets(text) != NULL) {
line = new char[strlen(text)+3];//动态字节分配
itoa(line_num, line, 10); //将十进制整数转换成字符串并赋予line
strcat(line, "."); //将字符串"."连接到line
strcat(line, text); //将text连接到line
cout << line << endl;
line_num++;
delete[]line; //释放line占据的内存字节
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -