Lecture Programming principles and practice using C++: Chapter 3 - Bjarne Stroustrup

Most programming tasks involve manipulating data. In this chapter, we will: Describe how to input and output data, present the notion of a variable for holding data, introduce the central notions of “Type” and “Type Safety”. | Chapter 3 Objects, types, and values Bjarne Stroustrup Abstract Most programming tasks involve manipulating data. Today, we will: describe how to input and output data present the notion of a variable for holding data introduce the central notions of “Type” and “Type Safety” Stroustrup/Programming/2015 Overview Strings and string I/O Integers and integer I/O Types and objects Type safety Stroustrup/Programming/2015 Input and output // read first name: #include "" // our course header int main() { cout > first_name; cout Stroustrup/Programming/2015 Overview Strings and string I/O Integers and integer I/O Types and objects Type safety Stroustrup/Programming/2015 Input and output // read first name: #include "" // our course header int main() { cout > first_name; cout Stroustrup/Programming/2015 Source files "" is the header for our course Interfaces to libraries (declarations) #include "" My code My data (definitions) : : Stroustrup/Programming/2015 Input and type We read into a variable Here, first_name A variable has a type Here, string The type of a variable determines what operations we can do on it Here, cin>>first_name; reads characters until a whitespace character is seen (“a word”) White space: space, tab, newline, Stroustrup/Programming/2015 String input // read first and second name: int main() { cout > first >> second; // read two strings string name = first + ' ' + second; // concatenate strings // separated by a space cout << "Hello, "<< name << '\n'; } // I left out the #include "" to save space and // reduce distraction // Don’t forget it in real code

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.