【问题标题】:How to take istream pointer as parameter and use it in a function?如何将 istream 指针作为参数并在函数中使用?
【发布时间】:2015-03-05 03:42:09
【问题描述】:

我有一个函数getToken,我想传递一个istream 来读取和使用它。这是给定的代码。请帮助我了解在作为参数传递时如何使用 istream 指针。

Token getToken(istream *br, string& lexeme){
    return DONE;//ignore this statement, its part of my needs for istream
}

【问题讨论】:

  • 为什么不传递对istream 的引用? Token getToken(istream& br, string& lexeme)
  • +1 对弗兰克的评论 - 参考可能更有意义。另外,“使用 istream”是什么意思?如果您可以更具体地说明您需要做什么以及哪些不起作用,那么您获得可能对您有帮助的答案的机会就会增加。

标签: c++ pointers parameter-passing istream


【解决方案1】:

您可以像使用 C++ 中的任何其他指针一样使用它。例如:

char c;    
*br >> c;

char c;
br->get(c);

【讨论】:

    猜你喜欢
    • 2022-01-20
    • 2021-12-03
    • 2015-01-29
    • 1970-01-01
    • 1970-01-01
    • 2021-07-18
    • 1970-01-01
    • 1970-01-01
    • 2021-11-29
    相关资源
    最近更新 更多