<tfoot id='ie7nn'></tfoot>

      <small id='ie7nn'></small><noframes id='ie7nn'>

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

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

        noskipws对cin的影响

        时间:2024-08-14
              <bdo id='XCM1D'></bdo><ul id='XCM1D'></ul>

              <small id='XCM1D'></small><noframes id='XCM1D'>

              • <legend id='XCM1D'><style id='XCM1D'><dir id='XCM1D'><q id='XCM1D'></q></dir></style></legend>

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

                1. <i id='XCM1D'><tr id='XCM1D'><dt id='XCM1D'><q id='XCM1D'><span id='XCM1D'><b id='XCM1D'><form id='XCM1D'><ins id='XCM1D'></ins><ul id='XCM1D'></ul><sub id='XCM1D'></sub></form><legend id='XCM1D'></legend><bdo id='XCM1D'><pre id='XCM1D'><center id='XCM1D'></center></pre></bdo></b><th id='XCM1D'></th></span></q></dt></tr></i><div id='XCM1D'><tfoot id='XCM1D'></tfoot><dl id='XCM1D'><fieldset id='XCM1D'></fieldset></dl></div>
                  本文介绍了noskipws对cin的影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  据我所知,提取操作符会跳过开头的空格,并在遇到空格或流结尾时停止.noskipws 可用于停止忽略前导空格.

                  As I understand, the extraction operator skips the whitespace in the beginning and stops upon encountering a whitespace or end of stream. noskipws can be used to stop ignoring the leading whitespaces.

                  我在以下程序中使用了 noskipws.

                  I have the following program where I have used noskipws.

                  #include <iostream>
                  using namespace std;
                  
                  int main()
                  {
                      char name[128];
                  
                      cout<<"Enter a name ";
                      cin>>noskipws>>name;
                      cout<<"You entered "<<name<<"
                  ";
                  
                      cout<<"Enter another name ";
                      cin>>name;
                      cout<<"You entered "<<(int)name[0]<<"
                  ";
                  
                      return 0;
                  }
                  

                  我的查询是:

                  1. 如果我输入John"作为第一个输入,那么第二个 cin>> 操作不会等待输入并且不会将任何内容复制到目标,即名称数组.我希望第二个 cin>> 至少传输一个换行符或流的结尾,而不是仅仅将目标字符串设置为空.为什么会发生这种情况?

                  1. If I enter "John" as the first input, then the second cin>> operation does not wait for input and does not copy anything to the destination i.e. the name array. I expected second cin>> to transfer at-least a newline or end of stream, instead of just setting the destination string to empty. Why is this happening ?

                  当我输入John Smith"作为第一个 cin>> 语句的输入时,观察到同样的事情.为什么第二个 cin>> 语句不将空格或Smith"复制到目标变量?

                  The same thing is observed when I enter "John Smith" as the input for first cin>> statement. Why doesn't the second cin>> statement copy the space or "Smith" to the destination variable ?

                  以下是程序的输出:

                  Enter a name John
                  You entered John
                  Enter another name You entered 0
                  
                  
                  Enter a name John Smith
                  You entered John
                  Enter another name You entered 0
                  

                  谢谢!!!

                  推荐答案

                  >> 字符串的基本算法是:

                  The basic algorithm for >> of a string is:

                  skip whitespace
                  read and extract until next whitespace
                  

                  如果您使用noskipws,则跳过第一步.第一次读取后,您被定位在一个空白处,因此下一次(以及所有后续)读取将立即停止,不提取任何内容.

                  If you use noskipws, then the first step is skipped. After the first read, you are positionned on a whitespace, so the next (and all following) reads will stop immediatly, extracting nothing.

                  >> 到字符串永远不会将空格放入字符串中.更一般地,将 >>noskipws 一起使用是有问题的,因为空格始终是 >>> 的分隔符;准时使用它可能是有意义的,但通常应该在使用后立即重置.(一次可能有意义的情况是将 >> 用于 char.在这种情况下,流 always 提取一个字符.)

                  >> to a string will never put whitespace into the string. More generally, using >> with noskipws is problematic, since whitespace is always a separator for >>; it may make sense to use it punctually, but it should generally be reset immediately after it has been used. (The once case where it might make sense is when using >> to a char. In this case, the stream always extracts one character.)

                  这篇关于noskipws对cin的影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:缓冲和非缓冲流 下一篇:使用`cin &gt;&gt;后使用`getline(cin, s);`n;`

                  相关文章

                  <small id='VjuIu'></small><noframes id='VjuIu'>

                  • <bdo id='VjuIu'></bdo><ul id='VjuIu'></ul>
                  <tfoot id='VjuIu'></tfoot>

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

                      <legend id='VjuIu'><style id='VjuIu'><dir id='VjuIu'><q id='VjuIu'></q></dir></style></legend>