English 中文(简体)
管道投入数据
原标题:pipeline input data

我需要起草一个方案,利用档案或单壳(管道处理)的投入。 处理这一问题的最有效方式是什么? 我基本上需要按行文读到输入线,但是,投入可能是另一个方案的产出,可能来自壳体或档案。

增 编

问题回答

I can t find the comments link, so post an answer. As Eugen Constantin Dinca said, pipe or redirect just output to the standard input, so what your program need to do is read from standard input.

我不知道,正如你提到的那样,“直线”的含义是什么? 比如,玩弄互动模式? 如果是这样的话,在你发出终点站信号之前,在您的方案中应当有一席之地。


Edit:

int c;
while(-1 != (c = getchar()))
    putchar(c);

https://stackoverflow.com/questions/3793498/echo-all-palindromes-in-c/3794956#3794956。 Echo All Palindromes, in C:

int main(int argc, char* argv[]) {
  int exit_code = NO_MATCH;
  if (argc == 1) // no input file; read stdin
    exit_code = palindromes(stdin);
  else {
    // process each input file
    FILE *fp = NULL;
    int ret = 0;
    int i;
    for (i = 1; i < argc; i++) { 
      if (strcmp(argv[i], "-") == 0)
        ret = palindromes(stdin);
      else if ((fp = fopen(argv[i], "r")) != NULL) {
        ret = palindromes(fp);
        fclose(fp);
      } else {
        fprintf(stderr, "%s: %s: could not open: %s
",
                argv[0], argv[i], strerror(errno));
        exit_code = ERROR;
      }
      if (ret == ERROR) {
        fprintf(stderr, "%s: %s: error: %s
",
                argv[0], argv[i], strerror(errno));
        exit_code = ERROR;
      } else if (ret == MATCH && exit_code != ERROR) 
        // return MATCH if at least one line is a MATCH, propogate error
        exit_code = MATCH;
    }
  }
  return exit_code;
}

为适应C++:接受<代码>std:istream&的书写功能(palindromes;通过std: (关于标准投入或——文档名称)或ifstreams from the

使用<代码>std:getline() with a given std:istream 功能内的物体按行文改为输入线(功能对输入是否来自档案或线)。

我认为,你希望与你一道工作。 但是,从我知道的其他方案来看,必须将其产出写给指定管道(如果你能够利用这一方案),你的方案将从指定管道读到。

Hope this helps you.

I might be misinterpreting the question but I think you want your program to be able to be used like this: cat [some_file] | [your_program] or [your program] < [some_file].
If that s the case than you just need to read from the standard input (stdin/cin), the shell will take care of the rest.

如果你想要从中或从档案中读到你的节目,你可以做些什么,即:

cat [OPTION] [FILE]...
...
With no FILE, or when FILE is -, read standard input.

上文所用代码样本见ts





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签