C_shell
目录
文章目录
1.追加分配内存(realloc)
2.退出程序(exit)
3.错误信息写入(fprintf)
3.1判断错误信息注意
4.读取一行(fgets)
4.1c++(getline)
#include <iostream>
#include <string>
int main() {
std::string line;
std::cout << "Please enter a line of text:" << std::endl;
// 使用默认分隔符(换行符)
std::getline(std::cin, line);
std::cout << "You entered: " << line << std::endl;
// 使用自定义分隔符
char delim = '#';
std::getline(std::cin, line, delim);
std::cout << "You entered until the delimiter '#': " << line << std::endl;
return 0;
}
5.查找第一次出现的字符位置(strchr)![请添加图片描述](https://img-blog.csdnimg.cn/direct/70698487d81141c5a19772e6d99794dd.png)
#include <stdio.h>
#include <string.h>
int main() {
const char *myString = "Hello, World!";
char targetChar = 'W';
char *found = strchr(myString, targetChar);
if (found != NULL) {
printf("Found '%c' at position: %zu\n", targetChar, found - myString);
} else {
printf("'%c' not found in the string.\n", targetChar);
}
return 0;
}
6.打印错误信息(perror)
7.显示类型转换
7.1 C
7.2 C++
8.函数安全警告(localtime)