peri hokiperihokiclarustologisticsrimashaop.comfenomena gates of olympus buka peluang besar bagi duta76cara dapat pola emas rahasia di duta7 wild west goldtrik menang pgsoft mahjong ways 2 modal receh maxwin duta76duta76 main pgsoft mahjong ways 2 di sela istirahatscatter hitam mahjong wins 3 spin pasti jepe duta76pola petir tersembunyi gates of olympus perihokipgsoft perkuat mahjong ways 2 di akun perihokiperihoki beri pola jitu mahjong wins 3 auto maxwinexclusive perihoki gates of olympus hadirkan fitur super scatterpgsoft mahjong ways perihoki punya irama scatter sendiripola jitu scatter hitam mahjong wins 3 auto maxwin di perihokiakun baru langsung panen di gates of olympus di duta76cara buat akun duta76 menjadi gacor main mahjong ways 2 pgsoftmahjong wins 3 duta76 viral karena tembus maxwin dalam 7 menitcuan 10rb scatter mahjong wayssantai main mahjong wins gacorscatter emas 257jt mahjong winspegawai menang mahjong awsbetteknik menang mahjong ways yang efektif

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 282

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: session_set_cookie_params(): Cannot change session cookie parameters when headers already sent

Filename: Session/Session.php

Line Number: 294

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 304

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 314

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 315

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 316

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 317

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 375

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: drivers/Session_files_driver.php

Line Number: 108

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: session_set_save_handler(): Cannot change save handler when headers already sent

Filename: Session/Session.php

Line Number: 110

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: session_start(): Cannot start session when headers already sent

Filename: Session/Session.php

Line Number: 143

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

Hàm cin() trong C / C++ - Freetuts
CÁC HÀM C / C++
CÁC CHỦ ĐỀ
BÀI MỚI NHẤT
MỚI CẬP NHẬT

Hàm cin() trong C / C++

Trong bài viết này chúng ta sẽ tìm hiểu về hàm cin trong C / C++. Đây là một hàm nhập xuất cơ bản của ngôn ngữ lập trình C++.

test php

banquyen png
Bài viết này được đăng tại freetuts.net, không được copy dưới mọi hình thức.

Hàm cin là hàm có sẵn trong thư viện iostream, vì vậy trước khi sử dụng nó các bạn nhớ khai báo thư viện đã nhé: #include<iostream>

Cú pháp hàm cin trong C / C++

Hàm cin là thể hiện của lớp iostream và được sử dụng để đọc đầu vào từ thiết bị nhập chuẩn, thường là bàn phím. Toán tử ">>" được sử dụng cùng với hàm cin để đọc đầu vào.

cin >> varName;

Ta có thể sử dụng nhiều lần để chấp nhận nhiều đầu vào.

Bài viết này được đăng tại [free tuts .net]

cin >> var1 >> var2 >> ... >> varN;

Hàm cin cũng có thể sử dụng với các hàm thành viên khác như getline(), read(),... Một số hàm thành viên thường được sử dụng là:

  • cin.get(char &ch): Đọc một ký tự đầu vào và lưu vào ch.
  • cin.getline (char * buffer, int length): Đọc một dòng ký tự vào bộ đệm chuỗi, nó sẽ dừng lại khi:
    • Đọc một ký tự.
    • Gặp "\n" ở cuối dòng hoặc cuối file.
  • cin.read (char * buffer, int n): Đọc n byte (hoặc cho đến khi kết thúc tệp) từ luồng vào bộ đệm.
  • cin.ignore (int n): Bỏ qua n ký tự tiếp theo từ luồng đầu vào.
  • cin.eof (): Trả về giá trị khác không nếu đạt đến cuối tệp (eof).

Cách dùng hàm cin trong C / C++

Trong phần này mình sẽ thực hiện hai ví dụ sử dụng hàm cin cùng với các hàm thành viên khác để các bạn có thể so sánh nhé.

Ví dụ 1: Ở ví dụ này mình sẽ sử dụng hàm cin kết hợp với hàm thành viên đó là getline() để đọc dữ liệu đầu vào. Cụ thể sẽ yêu cầu người dùng nhập vào tên và địa chỉ, sau đó xuất ra màn hình.

#include <iostream>
using namespace std;
int main() {
  //khai báo hai biến name và address kiểu char với độ dài 20
  char name[20], address[20];
	//sử dụng hàm cin để yêu cầu nhập tên
	cout << "Nhập tên: ";
	cin.getline(name, 20);
	//sử dụng hàm cin để yêu cầu nhập địa chỉ
	cout << "Nhập địa chỉ: ";
	cin.getline(address, 20);
	//sử dụng hàm cout để xuất các thông tin vừa nhập
	cout << endl << "Bạn đã nhập: " << endl;
	cout << "\tTên: " << name << endl;
	cout << "\tĐịa chỉ: " << address << endl;

  cout<<"\n---------------------------------------------\n";
  cout<<"Chương trình này được đăng tại freetuts.net";
}

Kết quả:

cin 01 PNG

Ví dụ 2: Ở ví dụ này mình thực hiện đọc các số x, y, z từ bàn phím với hàm cin thông thường, rồi thực hiện tính tổng và in ra màn hình.

#include <iostream>
using namespace std;
int main() {
  //khai báo 3 biến x,y,x là số nguyên
  int x, y, z;
	
	//Yêu cầu nhập số x
	cout << "Nhập vào số x: ";
	cin >> x;
	//yêu cầu nhập 2 số y, z
	cout << "Nhập vào hai số y và z: ";
	cin >> y >> z;
	//tính tổng 3 số x,y,z
	cout << "Tổng = " << (x+y+z);

  cout<<"\n---------------------------------------------\n";
  cout<<"Chương trình này được đăng tại freetuts.net";
}

Kết quả:

cin 02 PNG

Như vậy là chúng ta đã tìm hiểu xong hàm cin trong C / C++. Ở bài tiếp theo mình tiếp tục giới thiệu các hàm nhập xuất khác trong C++, các bạn chú ý theo dõi nhé !!!

Danh sách các hàm iostream

Cùng chuyên mục:

Các hàm xử lý mảng đa chiều (array.h) trong C/C++

Các hàm xử lý mảng đa chiều (array.h) trong C/C++

Các hàm xử lý ngày tháng (datetime.h) trong C/C++

Các hàm xử lý ngày tháng (datetime.h) trong C/C++

Các hàm xử lý số thực (float.h) trong C/C++

Các hàm xử lý số thực (float.h) trong C/C++

Các hàm xử lý số nguyên lớn (bigint.h) trong C/C++

Các hàm xử lý số nguyên lớn (bigint.h) trong C/C++

Các hàm xử lý thời gian (time.h) trong C

Các hàm xử lý thời gian (time.h) trong C

Các hàm xử lý chuỗi (string.h) trong C/C++

Các hàm xử lý chuỗi (string.h) trong C/C++

Thread Pools và Parallel Algorithms trong C++

Thread Pools và Parallel Algorithms trong C++

Tạo và quản lý các Multithreading trong C++

Tạo và quản lý các Multithreading trong C++

Xử lý ngoại lệ khi làm việc với Memory Allocation trong C++

Xử lý ngoại lệ khi làm việc với Memory Allocation trong C++

Try, Catch, và Throw của Exception Handling trong C++

Try, Catch, và Throw của Exception Handling trong C++

Cách sử dụng Lambda Expressions trong C++

Cách sử dụng Lambda Expressions trong C++

Sử dụng weak_ptr trong C++

Sử dụng weak_ptr trong C++

Sử dụng shared_ptr trong C++

Sử dụng shared_ptr trong C++

Sử dụng unique_ptr trong C++

Sử dụng unique_ptr trong C++

Tổng quan về Smart Pointers trong C++

Tổng quan về Smart Pointers trong C++

Sử dụng Iterators trong STL của C++

Sử dụng Iterators trong STL của C++

[Iterator] Sử dụng Vector trong C++

[Iterator] Sử dụng Vector trong C++

[Iterator] Sử dụng trong List trong C++

[Iterator] Sử dụng trong List trong C++

[STL] Sử dụng Vector trong C++

[STL] Sử dụng Vector trong C++

Tổng quan về Iterators trong C++

Tổng quan về Iterators trong C++

Top