1. 使用`printf`函数,配合格式化字符串`%s`来输出字符串。例如:
include
int main() {
char str[] = "Hello, world!";
printf("%s\n", str);
return 0;
}
2. 使用`puts`函数,该函数会自动在输出的字符串末尾添加换行符`\n`。例如:
include
int main() {
char str[] = "Hello, world!";
puts(str);
return 0;
}
3. 使用`echo`命令(在命令行环境中),可以输出字符串。例如,在Linux或macOS系统中:
echo "hello, world"
在Windows系统中,使用`cmd`命令行:
echo hello, world
4. 在Python中,可以使用`print`函数输出字符串。例如:
name = "ming"
position = "讲师"
address = "中山市平区建材城西路金燕龙办公楼1层"
print("--------------------------------------------------")
print("姓名:%s" % name)
print("职位:%s" % position)
print("公司地址:%s" % address)
print("--------------------------------------------------")
以上是几种常见的输出字符串的方法。