1. <tfoot id='8yhDc'></tfoot>

      <small id='8yhDc'></small><noframes id='8yhDc'>

          <bdo id='8yhDc'></bdo><ul id='8yhDc'></ul>

        <legend id='8yhDc'><style id='8yhDc'><dir id='8yhDc'><q id='8yhDc'></q></dir></style></legend>
      1. <i id='8yhDc'><tr id='8yhDc'><dt id='8yhDc'><q id='8yhDc'><span id='8yhDc'><b id='8yhDc'><form id='8yhDc'><ins id='8yhDc'></ins><ul id='8yhDc'></ul><sub id='8yhDc'></sub></form><legend id='8yhDc'></legend><bdo id='8yhDc'><pre id='8yhDc'><center id='8yhDc'></center></pre></bdo></b><th id='8yhDc'></th></span></q></dt></tr></i><div id='8yhDc'><tfoot id='8yhDc'></tfoot><dl id='8yhDc'><fieldset id='8yhDc'></fieldset></dl></div>
      2. 更改 cin (c++) 的分隔符

        时间:2024-08-14
          <tbody id='L24Lb'></tbody>

        • <tfoot id='L24Lb'></tfoot>
          1. <small id='L24Lb'></small><noframes id='L24Lb'>

            • <bdo id='L24Lb'></bdo><ul id='L24Lb'></ul>
              <i id='L24Lb'><tr id='L24Lb'><dt id='L24Lb'><q id='L24Lb'><span id='L24Lb'><b id='L24Lb'><form id='L24Lb'><ins id='L24Lb'></ins><ul id='L24Lb'></ul><sub id='L24Lb'></sub></form><legend id='L24Lb'></legend><bdo id='L24Lb'><pre id='L24Lb'><center id='L24Lb'></center></pre></bdo></b><th id='L24Lb'></th></span></q></dt></tr></i><div id='L24Lb'><tfoot id='L24Lb'></tfoot><dl id='L24Lb'><fieldset id='L24Lb'></fieldset></dl></div>

                1. <legend id='L24Lb'><style id='L24Lb'><dir id='L24Lb'><q id='L24Lb'></q></dir></style></legend>
                  本文介绍了更改 cin (c++) 的分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我已重定向cin"以从文件流中读取cin.rdbug(inF.rdbug())当我使用提取运算符时,它会一直读取直到遇到一个空白字符.

                  I've redirected "cin" to read from a file stream cin.rdbug(inF.rdbug()) When I use the extraction operator it reads until it reaches a white space character.

                  是否可以使用其他分隔符?我浏览了 cplusplus.com 中的 api,但没有找到任何东西.

                  Is it possible to use another delimiter? I went through the api in cplusplus.com, but didn't find anything.

                  推荐答案

                  可以更改 cin 或任何其他std::istream,使用std::ios_base::imbue 添加自定义 ctype facet.

                  如果您正在读取/etc/passwd 样式的文件,以下程序将分别读取每个 :-分隔的单词.

                  If you are reading a file in the style of /etc/passwd, the following program will read each :-delimited word separately.

                  #include <locale>
                  #include <iostream>
                  
                  
                  struct colon_is_space : std::ctype<char> {
                    colon_is_space() : std::ctype<char>(get_table()) {}
                    static mask const* get_table()
                    {
                      static mask rc[table_size];
                      rc[':'] = std::ctype_base::space;
                      rc['
                  '] = std::ctype_base::space;
                      return &rc[0];
                    }
                  };
                  
                  int main() {
                    using std::string;
                    using std::cin;
                    using std::locale;
                  
                    cin.imbue(locale(cin.getloc(), new colon_is_space));
                  
                    string word;
                    while(cin >> word) {
                      std::cout << word << "
                  ";
                    }
                  }
                  

                  这篇关于更改 cin (c++) 的分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  <i id='fOS1t'><tr id='fOS1t'><dt id='fOS1t'><q id='fOS1t'><span id='fOS1t'><b id='fOS1t'><form id='fOS1t'><ins id='fOS1t'></ins><ul id='fOS1t'></ul><sub id='fOS1t'></sub></form><legend id='fOS1t'></legend><bdo id='fOS1t'><pre id='fOS1t'><center id='fOS1t'></center></pre></bdo></b><th id='fOS1t'></th></span></q></dt></tr></i><div id='fOS1t'><tfoot id='fOS1t'></tfoot><dl id='fOS1t'><fieldset id='fOS1t'></fieldset></dl></div>

                2. <legend id='fOS1t'><style id='fOS1t'><dir id='fOS1t'><q id='fOS1t'></q></dir></style></legend>

                      <bdo id='fOS1t'></bdo><ul id='fOS1t'></ul>

                    • <small id='fOS1t'></small><noframes id='fOS1t'>

                        <tbody id='fOS1t'></tbody>
                          <tfoot id='fOS1t'></tfoot>