l******t 发帖数: 12659 | 1 向大家请教一个问题:
1. 编译文件: g++ -o exec prog.cpp
2. 重定向: exec < folder > output
目的是打算从folder里面寻找所需要的文件,然后处理后,将结果保存到output
请问,我在主程序中,如何得到folder的名字;里面的文件等信息啊?
多谢了! | X****r 发帖数: 3557 | 2 Redirection does not work like this. Redirecting input of a program
from a file means that the standard input (file descriptor 0, which
corresponds to stdin in C or cin in C++) would be from this file
instead of from a console (where you type). However, directory
is a special kind of file so it probably wouldn't work for you here.
If your program can read the list of files from standard input and
examine them, you can do
(assuming . is in your path, otherwise you need to use ./prog)
g++ -o prog
【在 l******t 的大作中提到】 : 向大家请教一个问题: : 1. 编译文件: g++ -o exec prog.cpp : 2. 重定向: exec < folder > output : 目的是打算从folder里面寻找所需要的文件,然后处理后,将结果保存到output : 请问,我在主程序中,如何得到folder的名字;里面的文件等信息啊? : 多谢了!
| c*m 发帖数: 1114 | 3 Redirection is not appropriate here.
It should like "exec foldername outputfilename".
And you may use to access files inside the specific folder(opendi
r or whatever). And finally write output to "outputfilename".
Check this thread
http://www.linuxquestions.org/questions/programming-9/c-list-files-in-direct
ory-379323/
BTW, if you have to use "< folder" and ">output", you may read folder name
as a string and do the same thing on above.
【在 l******t 的大作中提到】 : 向大家请教一个问题: : 1. 编译文件: g++ -o exec prog.cpp : 2. 重定向: exec < folder > output : 目的是打算从folder里面寻找所需要的文件,然后处理后,将结果保存到output : 请问,我在主程序中,如何得到folder的名字;里面的文件等信息啊? : 多谢了!
| l******t 发帖数: 12659 | 4 非常感谢两位的回复!!!
我也不知道为什么那个题目重定向stdin到文件夹
不过, wc的命令似乎也可以将stdin重定向到文件夹
link: http://blog.chinaunix.net/u1/56343/showart_442411.html |
|