我对此非常困惑.需要一些澄清.
例1:
pgrep string | xargs ps
Run Code Online (Sandbox Code Playgroud)
例2:
find . | xargs grep whatever
Run Code Online (Sandbox Code Playgroud)
从例1开始,我就是这样收集的:
搜索一个"字符串",它是正在运行的进程名称的一部分,并将所有匹配的进程ID返回给'xargs ps' - >,它只是将ps附加到匹配项(它们是process-id本身)以获得相同的输出为:
ps <processid>
Run Code Online (Sandbox Code Playgroud)
有人能解释一下xargs在这种情况下的真正作用吗?
从例2开始,我就是这样收集的:
它是从当前工作目录中递归搜索一些"字符串".在这里,'xargs'究竟是如何工作的?
我认为'xargs'反复将标准输入的数据附加到给予xargs(通常是UNIX命令本身)的'参数'.
来自xargs()手册页:
xargs从标准输入中读取项目,由空格分隔(可以使用双引号或单引号或反斜杠保护)或换行符,并使用任何初始参数执行命令(默认为/ bin/echo)一次或多次从标准输入读取的项目.标准输入上的空行将被忽略.
基本问题.
char new_str[]="";
char * newstr;
Run Code Online (Sandbox Code Playgroud)
如果我必须将一些数据连接到它或使用字符串函数如strcat/substr/strcpy,两者之间的区别是什么?
我知道我必须为char*方法分配内存(第2行).我不太确定如何.
const char*和字符串文字是一样的吗?
我需要了解更多.有人能指出一些不错的详尽内容/材料吗?
{net04:~/xxxx/wip} gcc -o write_test write_test.c
In file included from write_test.c:4:
global.h:10: warning: `b' initialized and declared `extern'
Run Code Online (Sandbox Code Playgroud)
此代码使用fcntl.h和定义的文件处理函数 - 如open(),write(),close()等.代码编译并按预期工作.
{net04:~/xxxx/wip} gcc -o write_test write_test.cpp
In file included from write_test.cpp:4:
global.h:10: warning: `b' initialized and declared `extern'
write_test.cpp: In function `int main()':
write_test.cpp:56: error: `exit' undeclared (first use this function)
write_test.cpp:56: error: (Each undeclared identifier is reported only once for each function it appears in.)
write_test.cpp:58: error: `write' undeclared (first use this function)
write_test.cpp:62: error: `close' undeclared (first use this …Run Code Online (Sandbox Code Playgroud) 这种建立在已经问过的问题上 ...但是,在这里,比方说,我给了一个十六进制输入,可能是'0xFFFF'的最大值我需要将它转换为二进制,这样我最终会得到最多16位.
我想知道如果使用'bitset'它会很简单..任何想法?
编辑:
得到答案后,这里有一段即兴的代码:http://pastebin.com/f7a6f0a69
以下两个片段之间有什么区别吗?一个是char数组,而另一个是字符数组指针,但它们的行为相同,不是吗?
例1:
char * transport_layer_header;
// Memory allocation for char * - allocate memory for a 2 character string
char * transport_layer_header = (char *)malloc(2 * sizeof(char));
sprintf(transport_layer_header,"%d%d",1,2);
Run Code Online (Sandbox Code Playgroud)
例2:
char transport_layer_header[2];
sprintf(transport_layer_header,"%d%d",1,2);
Run Code Online (Sandbox Code Playgroud) 我无法理解编译器.以下代码在g ++下的UNIX中可以正常工作,但在VC++下它甚至不能编译.任何人都可以提供有效理由吗?
#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
string tmp_nw_msg, crc_chksum, buffer;
cout << "Enter the string : ";
cin >> buffer;
if (strlen(buffer.c_str()) >15 ) {
tmp_nw_msg = buffer.substr(1,12);
crc_chksum = buffer.substr(13,2);
cout << " N/W msg : "<< tmp_nw_msg << endl;
cout << " crc chksum : "<< crc_chksum << endl;
}
else {
cout << "error" << endl;
}
std::cin.get();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
VC++抛出以下错误,但在g ++中它确实可以正常工作.
错误1错误C2679:二进制'>>':找不到哪个运算符采用'std :: string'类型的右手操作数(或者没有可接受的转换)c:\ documents and settings\my …