ผลต่างระหว่างรุ่นของ "Ske algo lab/read input"

จาก Theory Wiki
ไปยังการนำทาง ไปยังการค้นหา
แถว 8: แถว 8:
 
== Detecting EOF for getline ==
 
== Detecting EOF for getline ==
  
You can use <tt>std::getline</tt> to read the whole line.  The following is the template for TEX quotes.
+
You can use <tt>std::getline</tt> to read the whole line.  The following is the template for TEX quotes.  You can access string length with <tt>length</tt> method and you can access each character using []. See [http://www.cplusplus.com/reference/string/string/ reference here].
  
 
<syntaxhighlight lang="cpp">
 
<syntaxhighlight lang="cpp">

รุ่นแก้ไขเมื่อ 02:51, 23 สิงหาคม 2562

This is part of Ske algo lab.

Detecting EOF for cin

This is the template for 3n+1.


Detecting EOF for getline

You can use std::getline to read the whole line. The following is the template for TEX quotes. You can access string length with length method and you can access each character using []. See reference here.

#include <iostream>
#include <string>

using namespace std;

int main()
{
  string st;
  while(getline(cin, st)) {
    // ...
  }
}