logo

C++ Manipulator endl

C++ manipulator endl הפונקציה משמשת להוספת תו קו חדש ולשטוף את הזרם.

העבודה של manipulator endl דומה לתו ' ' ב-C++. הוא מדפיס את הפלט של ההצהרה הבאה בשורה הבאה.

תחביר

 for ostream ostream& endl (ostream& os); basic template template basic_ostream& endl (basic_ostream& os); 

פָּרָמֶטֶר

אתה : אובייקט זרם הפלט מושפע.

ערך החזרה

זה מחזיר טיעון אתה .

מירוצי נתונים

משנה את מערכת ההפעלה של אובייקט הזרם.

אם ננסה לגשת במקביל לאותו אובייקט זרם, אז זה עלול לגרום למירוצי נתונים, למעט אובייקטי הזרם הסטנדרטיים cerr, cout, wcout, clog, wcerr ו-wclog כאשר אלה מסונכרנים עם stdio.

בטיחות חריגה

לְהִתְנַגֵד אתה נמצא במצב חוקי, אם נזרק חריג כלשהו.

מה זה אובייקט ג'אווה

דוגמה 1

בואו נראה את הדוגמה הפשוטה להדגמת השימוש ב-endl:

 #include using namespace std; int main() { cout << 'Hello' << endl << 'World!'; return 0; } 

תְפוּקָה:

 Hello World! 

דוגמה 2

בוא נראה עוד דוגמה פשוטה:

 #include using namespace std; int main() { int num; cout&lt;&gt;num; cout&lt;<'hello roll number '<<num<<endl; cout<<'welcome to your new class!!'; return 0; } < pre> <p> <strong>Output:</strong> </p> <pre> Enter your roll number: 22 Hello roll number 22 Welcome to your new class!! </pre> <h2>Example 3</h2> <p>Let&apos;s see another simple example:</p> <pre> #include // std::cout, std::end using namespace std; int main () { int a=100; double b=3.14; cout &lt;&lt; a; cout &lt;&lt; endl; // manipulator inserted alone cout &lt;&lt; b &lt;&lt; endl &lt;&lt; a*b; // manipulator in concatenated insertion endl (cout); // endl called as a regular function return 0; } </pre> <p> <strong>Output:</strong> </p> <pre> 100 3.14 314 </pre> <h2>Example 4</h2> <p>Let&apos;s see another simple example:</p> <pre> #include #include using namespace std; template void log_progress(Diff d) { cout &lt;&lt; chrono::duration_cast(d).count() &lt;&lt; &apos; ms passed&apos; &lt;&lt; endl; } int main() { cout.sync_with_stdio(false); // on some platforms, stdout flushes on 
 volatile int sink = 0; auto t1 = chrono::high_resolution_clock::now(); for (int j=0; j<5; ++j) { for (int n="0;" n<10000; ++n) m="0;" m<20000; ++m) sink +="m*n;" do some work auto now="chrono::high_resolution_clock::now();" log_progress(now - t1); } return 0; < pre> <p> <strong>Output:</strong> </p> <pre> 435 ms passed 894 ms passed 1326 ms passed 1747 ms passed 2178 ms passed </pre></5;></pre></'hello>

דוגמה 3

בוא נראה עוד דוגמה פשוטה:

 #include // std::cout, std::end using namespace std; int main () { int a=100; double b=3.14; cout &lt;&lt; a; cout &lt;&lt; endl; // manipulator inserted alone cout &lt;&lt; b &lt;&lt; endl &lt;&lt; a*b; // manipulator in concatenated insertion endl (cout); // endl called as a regular function return 0; } 

תְפוּקָה:

 100 3.14 314 

דוגמה 4

בוא נראה עוד דוגמה פשוטה:

 #include #include using namespace std; template void log_progress(Diff d) { cout &lt;&lt; chrono::duration_cast(d).count() &lt;&lt; &apos; ms passed&apos; &lt;&lt; endl; } int main() { cout.sync_with_stdio(false); // on some platforms, stdout flushes on 
 volatile int sink = 0; auto t1 = chrono::high_resolution_clock::now(); for (int j=0; j<5; ++j) { for (int n="0;" n<10000; ++n) m="0;" m<20000; ++m) sink +="m*n;" do some work auto now="chrono::high_resolution_clock::now();" log_progress(now - t1); } return 0; < pre> <p> <strong>Output:</strong> </p> <pre> 435 ms passed 894 ms passed 1326 ms passed 1747 ms passed 2178 ms passed </pre></5;>