- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
打印格式字符串如何作为参数传递?
例子.cpp:
#include <iostream>
int main(int ac, char* av[])
{
printf(av[1],"anything");
return 0;
}
尝试:
example.exe "print this\non newline"
输出是:
print this\non newline
相反,我想要:
print this
on newline
最佳答案
不,不要那样做!这是一个非常严重的漏洞。你不应该接受格式字符串作为输入。如果您想在看到“\n”时打印换行符,更好的方法是:
#include <iostream>#include <cstdlib>int main(int argc, char* argv[]){ if ( argc != 2 ){ std::cerr << "Exactly one parameter required!" << std::endl; return 1; } int idx = 0; const char* str = argv[1]; while ( str[idx] != '\0' ){ if ( (str[idx]=='\\') && (str[idx+1]=='n') ){ std::cout << std::endl; idx+=2; }else{ std::cout << str[idx]; idx++; } } return 0;}
或者,如果您在项目中包含 Boost C++ 库,则可以使用 boost::replace_all
函数将“\\n”的实例替换为“\n”,如建议的那样来自 Pukku。
关于C++ 打印 : newline (\n) from commandline argument,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2508796/
Swift 标准库将 CommandLine 声明为枚举。 /// Command-line arguments for the current process. public enum Comman
我正在尝试将预构建 shell 脚本添加到我的 gradle/Android-Studio 构建中。我已将以下内容添加到 app/build.gradle: task prePreBuild << {
我正在尝试使用 System.CommandLine,但无法让我的处理程序查看我传入的任何值。我尝试了最简单的命令行程序只是为了查看是否有任何值成功了,但到目前为止我还没有成功。我的目标是 .NET
在 gradle 中,有什么理由不使用 Groovy 的 .execute() 函数来运行命令行进程?我知道“gradle”方式是来自 Exec 的命令行。但感觉 .execute() 提供了更多的灵
使用根命令: new RootCommand { new Option("--myoption") }; 你怎么区分 ./myapp 和 ./myapp --myoption "" ? 我最初
我确信这会很简单,但找不到任何文档或解决方案。 我正在尝试使用 gcloud 编写脚本以在我的 GCP 实例中执行一些操作。 无论如何只能通过命令行使用 gcloud 登录/验证吗? 谢谢 最佳答案
在 $HOME/.gradle/init.gradle我有: gradle.buildFinished { buildResult -> commandLine 'bash', "blah b
我正在使用来自 nuget 的命令行库 v 1.9.71.2。不幸的是,文档不是最新的,而且我不了解用于此库的高级 C# 语言结构,因此我无法仅通过查看库中可用的接口(interface)来提出可行的
对于单元测试,我想模仿不同的命令行参数。如何在运行时将 commandLine args 修改为我的程序(环顾四周但找不到技巧)?基本上,我试图找到一种方法来修改 READONLY 属性 Enviro
我有一个 C++ 应用程序,它使用 CCommandLineInfo 来解析命令行参数。 其中一个参数是我们在应用程序启动后使用 CryptProtectMemory 在内存中加密的密码。 那时我想摆
我已经使用 CommandLine 库来解析它通过字符串类型、int 类型、bool 类型但它不能通过字节类型,我有一个异常 “Bad default value.” [Option("m",
我有一个项目正在向 Chrome 浏览器添加一些特定的标志(命令行),问题是我通过创建一个新的 Chrome 快捷方式来执行此操作,其中包含我想要执行的标志。 在过去的几天里,这个解决方案变得过于肤浅
我正在尝试使用 System.CommandLine 并且我已经安装了 nuget 包: Install-Package System.CommandLine -Version 2.0.0-beta1
我想在 gradle 任务中从命令行执行一些命令(例如打印目录中的所有文件): task dir(type: Exec) { def adbCommand = ["dir", "*.*"] c
使用 Command Line Parser Library , 有没有办法标记一组 say 3 选项并准确地制作所需的三个选项之一? 所以有这些选择: [Option("list-plugins",
$ mongo MongoDB shell version: 2.0.0 connecting to: test > use admin switched to db admin > db.auth(
我想使用 org.apache.commons.exec Java 库来调用可执行文件。 CommandLine对象防止命令行注入(inject)?例如,如果我调用: String singleStr
打印格式字符串如何作为参数传递? 例子.cpp: #include int main(int ac, char* av[]) { printf(av[1],"anything");
请在下面找到我的 dom xml 示例。我正在运行命令 virsh create 并收到此错误: Unable to open file 这个文件的权限都很好。 qemu:commandline下的
起初:我知道命令行中tsc和tsc -w的区别。这不是问题,而是一种特殊情况: 在 VS Code 的 tsconfig 中,我通过设置 "watch":true 启用了观察器。这是绝对想要的。但是现
我是一名优秀的程序员,十分优秀!