连接到c+的窗口管道+;程序 我有以下C++程序: #include <iostream> using namespace std; //will find the last dot and return it's location char * suffix_location(char *); int main(int argc, char* argv[]) { if (argc < 2) { cout << "not enough arguments!" << endl; for (int i = 0; i < argc; i++) cout << argv[i] <<endl; exit(1); } //ignore first parameter (program name). argv ++; argc --; //the new suffix char * new_suffix = argv[0]; argv++; argc--; for (int i = 0; i < argc; i++) { char * a = suffix_location(argv[i]); if (a != NULL) { a[0] = NULL; cout << argv[i] << '.' << new_suffix << endl; } } return 0; } char * suffix_location(char * file_name) { char * ret = NULL; for (; * file_name; file_name++) if (*file_name == '.') ret = file_name; return ret; }
当我跑的时候连接到c+的窗口管道+;程序 我有以下C++程序: #include <iostream> using namespace std; //will find the last dot and return it's location char * suffix_location(char *); int main(int argc, char* argv[]) { if (argc < 2) { cout << "not enough arguments!" << endl; for (int i = 0; i < argc; i++) cout << argv[i] <<endl; exit(1); } //ignore first parameter (program name). argv ++; argc --; //the new suffix char * new_suffix = argv[0]; argv++; argc--; for (int i = 0; i < argc; i++) { char * a = suffix_location(argv[i]); if (a != NULL) { a[0] = NULL; cout << argv[i] << '.' << new_suffix << endl; } } return 0; } char * suffix_location(char * file_name) { char * ret = NULL; for (; * file_name; file_name++) if (*file_name == '.') ret = file_name; return ret; },c++,visual-studio-2010,windows-7,piping,C++,Visual Studio 2010,Windows 7,Piping,当我跑的时候 switch_suffix py a.exe b.txt 我得到: a.py b.py 正如所料 当我试着吹管时,问题就开始了。运行以下命令: dir /B | swich_suffix py 结果什么都没有,并且正在运行 dir /B | swich_suffix py 结果: not enough arguments! switch_suffix 系统上的管道工作正常-我在其他几个程序上试过 我试着创建一个vs项目并从中编译代码,但毫无帮助 怎么了,我能修一下吗
switch_suffix py a.exe b.txt
我得到:
a.py
b.py
正如所料当我试着吹管时,问题就开始了。运行以下命令:
dir /B | swich_suffix py
结果什么都没有,并且正在运行
dir /B | swich_suffix py
结果:
not enough arguments!
switch_suffix
系统上的管道工作正常-我在其他几个程序上试过我试着创建一个vs项目并从中编译代码,但毫无帮助 怎么了,我能修一下吗
我在win7上运行,使用vs2010工具。当你使用管道时,传递给你的程序的信息在标准输入上,而不是argv当你使用管道时,传递给你的程序的信息在标准输入上,而不是在main中的参数上 这段代码将在
stdin
上接收到的内容打印到stdout
,请尝试以下操作:
for (std::string line; std::getline(std::cin, line);) {
std::cout << line << std::endl;
}
for(std::string-line;std::getline(std::cin,line);){
std::cout当您通过管道传输到另一个程序时,它将转到标准输入,而不是main中的参数
这段代码将在stdin
上接收到的内容打印到stdout
,请尝试以下操作:
for (std::string line; std::getline(std::cin, line);) {
std::cout << line << std::endl;
}
for(std::string-line;std::getline(std::cin,line);){
STD::我尝试用<代码> CIN。GETLION <代码>将数据重新收集到<代码> char */COD>。它没有用。这两个之间是否存在真正的差异?是的,STD::String是一个C++中存储字符串的对象。内存是为您管理的,并且内置了很多漂亮的方法。<代码> char */COD>是指向一些字符的指针。你必须管理你自己。我强烈建议你在C++中使用STD::String。如果你决定使用<代码> char */Cube >,那么我就尝试用<代码> CIN。GETLION <代码>将数据重新收集到<代码> char */COD>。它不起作用。两者之间是否存在真正的差异?是的,STD::String是S的对象。C++ C++中的字符串的管理。内存是为你管理的,里面有很多漂亮的方法。<代码> char */COD>是你必须管理自己的一些字符的指针。我强烈建议你在使用C++时使用STD::String。如果你决定使用<代码> char */COD>