int main() { char a[101]; cout << "str a:"; gets(a); return 0; }
That's why gets(a);running up to cout<<"str a:";?
gets(a);
cout<<"str a:";
The compiler is used: digital mars and GNN_gcc.
Buffers gets()and coutvarious. Since nothing makes the coutbuffer hide, the contents remain in the buffer when execution reaches the function gets(). To make the result fit your expectation and order of execution:
gets()
cout
Option 1: use cout << "str a:" << endl;to force deletion of the contents of the buffer. You can also use flushif you do not need a new line.
cout << "str a:" << endl;
flush
2: /, / . , , cin >> a; getline, cin.
cin >> a;
getline
cin
, !
gets(a); cout<<"str a:";?
gets() cout<<"str a:";, flush() , :
flush()
cout<<"str a:" << flush;
.
@Slava answer, std::cin.
std::cin
, , flush().
gets() ( , ) C-, ,
std::ios::sync_with_stdio();
main() (. ).
main()
:
gets(), ++ 14,
std::string a; // Much more convenient than char a[100]; std::getline(std::cin,a);
(a); cout < "str a:";?
. , , cout , gets(). std::cout std::cin , . C- , std::cout , sync_with_stdio
std::cout
sync_with_stdio
Source: https://habr.com/ru/post/1668441/More articles:Dynamically change panning of an audio stream in Swift using an HLS source (m3u8) - iosWhat is the difference between Haskell's Floating and Fractional classes? - floating-pointBoolean matrix form Python dict lists - pythonSequentially accepting elements from a two-dimensional array (Java) - javaJavascript - Using the timeago function with Algolia autocomplete - javascriptCodeigniter REST API keys do not work - restПочему запуск std:: thread с пустой функцией тратит много памяти - c++F # lambda expression without parameters - lambdaFont error while creating new Geom in ggplot2 - rCreating a Web :: Scraper Object as a Class Attribute in Moose - perlAll Articles