SlideShare a Scribd company logo
1 of 22
Introduction to Information
System
Section 1
1
Github
• GitHub is a website and cloud-based
service that helps developers store and
manage their code, as well as track and
control changes to their code, mainly
used for:
• Version control
• Git
2
Version Control
• Version control helps developers track and manage
changes to a software project’s code. As a software
project grows, version control becomes essential.
– Branching, a developer duplicates part of the source
code. The developer can then safely make changes to
that part of the code without affecting the rest of the
project.
– Then, once the developer gets his or her part of the code
working properly, he or she can Merge that code back
into the main source code to make it official.
– All of these changes are then tracked and can be
reverted if need be.
3
Git
• Git is a specific open-source version
control system created by Linus
Torvalds in 2005.
• Git is a distributed version control
system, which means that the entire
codebase and history is available on
every developer’s computer, which allows
for easy branching and merging.
4
Create Github Account
• With a personal account on GitHub, you can
import or create repositories, collaborate with
others, and connect with the GitHub
community.
• To create a personal Github account:
1. Navigate to https://github.com/ and follow the
prompts.
2. Create a strong and unique password.
3. Choose GitHub Free account
4. verify your email address
5. Configure two-factor authentication
6. View your GitHub profile and dashboard
5
Git Bash
• Git Bash is an application for Microsoft
Windows environments which enables
you to interact with Github using a
command line called “Bash”.
• Git Bash is a package that installs Bash,
some common bash utilities, and Git on a
Windows operating system.
• You can download it from: https://git-
scm.com/downloads
6
Git for Desktop
• GitHub Desktop is an application that enables you
to interact with GitHub using a GUI instead of the
command line or a web browser.
• You can use GitHub Desktop to complete most
Git commands from your desktop with visual
confirmation of changes.
• You can push to, pull from, and clone remote
repositories with GitHub Desktop, and use
collaborative tools.
• Go to https://desktop.github.com/, download and
install it.
7
Git Commands
- git version: to check the version of the Git
installed on your machine.
- git init to initiate a local repository of the
project.
- git status to show modified files in working
directory, staged for your next commit (the
red files and folders are not committed to the
repo).
8
Git Commands
• git add <filename> : to add the files to the
staged area.
• git add *: to add all files.
• Now if we make a little change in any file and
save it and type checked the status again, we
can see the modified files with red so add
them again by (git add . ).
9
Git Commands
• To upload your project to GitHub, First u need to authenticate
yourself to Git bash/desktop
• Git config--global user.name "user-name“
• Git config--global user.email mail@gmail.com
• Git commit –m “first Commit”
• Now your project ready to be uploaded to the remote repository
• Go to the remote repository and get the link
• Then, we need to link the local repo to the remote repo, using this
command:
• git remote add origin https://github.com/testname/repoName.git
• git push -u origin master: To push the project to the remote
repository.
10
Git Commands
• Now Go To the branch that we have created,
and we can see all files of our test program
uploaded successfully.
• git clone https://
github.com/testname/repoName.git : to
clone the repo to our local device to work
with it this called (clone it).
• git checkout –b name: To make another
branch
11
File Handling in C++
• File are used to store data in a relatively
permanent form (e.g., on Hard disk, or other form
of secondary storage).
• Files can hold huge amounts of data if need.
• For achieving file handling, we need to follow the
following steps:
• Create a Handler Object
• Naming a file
• Opening a file
• Writing data into the file
• Reading data from the file
• Closing a file.
12
Streams in C++
• We give input to the executing program
and the execution program gives back the
output.
• Streams: the flow of data in a sequence of
bytes.
• The input and output operation between
the executing program and files are
known as “disk I/O operation”.
13
Classes for File stream operations
• Ofstream (output file stream):
– is used to create files and to write information to files.
– It can be accessed with the insertion operator ”<<“.
– It contains open() function with default output mode.
– Use the functions put() and write().
• ifstream (input file stream):
– is used to read information from files.
– It can be accessed with the extraction operator ”>>”.
– It contains open() function with default input mode.
– Use the functions get(), getline(), and read()
• Fstream
– This class provides support input and output operations.
– Use functions from istream and ostream classes
14
15
16
Create file and write text
• #include <iostream>
• #include <fstream>
• using namespace std;
• int main () {
• ofstream myfile;
• myfile.open ("example.txt");
• myfile << “Hello world.n";
• myfile.close();
• return 0;
• }
17
Reading a text file
• #include <iostream>
• #include <fstream>
• #include <string>
• using namespace std;
• int main () {
• string line;
• fstream myfile ("example.txt");
• if (myfile.is_open()) {
• while ( getline (myfile,line) ) {
• cout << line << 'n'; }
• myfile.close(); }
• else cout << "Unable to open file";
• return 0;
• }
18
Writing on a text file using is_open()
• #include <iostream>
• #include <fstream>
• using namespace std;
• int main () {
• ofstream myfile ("example.txt");
• if (myfile.is_open()) {
• myfile << "This is a line.n";
• myfile << "This is another line.n";
• myfile.close(); }
• else cout << "Unable to open file";
• return 0;
• }
19
Writing on a text file
• #include <iostream>
• #include <fstream>
• #include <string>
• using namespace std;
• int main(){
• ofstream fout("test.txt");
• if (!fout.is_open())
• cout << "File can not be opennedn";
• else fout << "Cairo, Damietta, Assiut, Aswan"<<endl;
• fout.close();
• return 0;
• }
20
Read lines of text file
• #include <iostream>
• #include <fstream>
• #include <string>
• using namespace std;
• int main(){
• ifstream f2;
• string line;
• int count = 0;
• f2.open("example.txt");
• while (getline(f2, line)) {
• cout << line << endl;
• count++; } //end while
• cout << "count of lines = " << count << endl;
• f2.close();
• } //end main 21
Writing then Reading from a Text File
using an Array of String
• int main(){
• char cities[200] = "Cairo, Damietta, Assiut, Aswan.";
• fstream f1;
• f1.open("section.txt", ios::out); //Open for writing
• if (!f1) { cout << "file can not foundn"; }
• else {
• for (int i = 0; i < strlen(cities); i++){
• f1.put(cities[i]); } }
• f1.close();
• fstream f2;
• string res = "";
• f2.open("section.txt", ios::in); //Open for reading
• if (!f2) { cout << "file can not foundn"; }
• else {
• while(!f2.eof()) {
• res += f2.get();}}
• cout << res << endl;
• f2.close();
• return 0;
• }
22

More Related Content

Similar to IS - section 1 - modifiedFinal information system.pptx

Introduction to git and githhub with practicals.pptx
Introduction to git and githhub with practicals.pptxIntroduction to git and githhub with practicals.pptx
Introduction to git and githhub with practicals.pptxAbdul Salam
 
git and github-1.pptx
git and github-1.pptxgit and github-1.pptx
git and github-1.pptxtnscharishma
 
Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners HubSpot
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github Max Claus Nunes
 
Untangling fall2017 week2_try2
Untangling fall2017 week2_try2Untangling fall2017 week2_try2
Untangling fall2017 week2_try2Derek Jacoby
 
Untangling fall2017 week2
Untangling fall2017 week2Untangling fall2017 week2
Untangling fall2017 week2Derek Jacoby
 
Luis atencio on_git
Luis atencio on_gitLuis atencio on_git
Luis atencio on_gitLuis Atencio
 
Embedded Systems: Lecture 10: Introduction to Git & GitHub (Part 1)
Embedded Systems: Lecture 10: Introduction to Git & GitHub (Part 1)Embedded Systems: Lecture 10: Introduction to Git & GitHub (Part 1)
Embedded Systems: Lecture 10: Introduction to Git & GitHub (Part 1)Ahmed El-Arabawy
 
Presentation for git jira and linux
Presentation for git jira and linuxPresentation for git jira and linux
Presentation for git jira and linuxdkylko1
 
Git is a distributed version control system .
Git is a distributed version control system .Git is a distributed version control system .
Git is a distributed version control system .HELLOWorld889594
 
Gitgithub101slideshare 150922131830-lva1-app6891
Gitgithub101slideshare 150922131830-lva1-app6891Gitgithub101slideshare 150922131830-lva1-app6891
Gitgithub101slideshare 150922131830-lva1-app6891Brian Okinyi
 
Hello Git
Hello GitHello Git
Hello Gitbsadd
 

Similar to IS - section 1 - modifiedFinal information system.pptx (20)

Git and Github
Git and GithubGit and Github
Git and Github
 
Introduction to git and githhub with practicals.pptx
Introduction to git and githhub with practicals.pptxIntroduction to git and githhub with practicals.pptx
Introduction to git and githhub with practicals.pptx
 
Mini git tutorial
Mini git tutorialMini git tutorial
Mini git tutorial
 
git and github-1.pptx
git and github-1.pptxgit and github-1.pptx
git and github-1.pptx
 
Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners
 
Hello, Git!
Hello, Git!Hello, Git!
Hello, Git!
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github
 
Untangling fall2017 week2_try2
Untangling fall2017 week2_try2Untangling fall2017 week2_try2
Untangling fall2017 week2_try2
 
Untangling fall2017 week2
Untangling fall2017 week2Untangling fall2017 week2
Untangling fall2017 week2
 
1-Intro to VC & GIT PDF.pptx
1-Intro to VC & GIT PDF.pptx1-Intro to VC & GIT PDF.pptx
1-Intro to VC & GIT PDF.pptx
 
Luis atencio on_git
Luis atencio on_gitLuis atencio on_git
Luis atencio on_git
 
Embedded Systems: Lecture 10: Introduction to Git & GitHub (Part 1)
Embedded Systems: Lecture 10: Introduction to Git & GitHub (Part 1)Embedded Systems: Lecture 10: Introduction to Git & GitHub (Part 1)
Embedded Systems: Lecture 10: Introduction to Git & GitHub (Part 1)
 
Mini-training: Let’s Git It!
Mini-training: Let’s Git It!Mini-training: Let’s Git It!
Mini-training: Let’s Git It!
 
Presentation for git jira and linux
Presentation for git jira and linuxPresentation for git jira and linux
Presentation for git jira and linux
 
GitHub Event.pptx
GitHub Event.pptxGitHub Event.pptx
GitHub Event.pptx
 
Git is a distributed version control system .
Git is a distributed version control system .Git is a distributed version control system .
Git is a distributed version control system .
 
Gitgithub101slideshare 150922131830-lva1-app6891
Gitgithub101slideshare 150922131830-lva1-app6891Gitgithub101slideshare 150922131830-lva1-app6891
Gitgithub101slideshare 150922131830-lva1-app6891
 
Hello Git
Hello GitHello Git
Hello Git
 
Techoalien git
Techoalien gitTechoalien git
Techoalien git
 
Techoalien git
Techoalien gitTechoalien git
Techoalien git
 

Recently uploaded

Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationNeilDeclaro1
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111GangaMaiya1
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningMarc Dusseiller Dusjagr
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptNishitharanjan Rout
 
latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answersdalebeck957
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 

Recently uploaded (20)

Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health Education
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answers
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 

IS - section 1 - modifiedFinal information system.pptx

  • 2. Github • GitHub is a website and cloud-based service that helps developers store and manage their code, as well as track and control changes to their code, mainly used for: • Version control • Git 2
  • 3. Version Control • Version control helps developers track and manage changes to a software project’s code. As a software project grows, version control becomes essential. – Branching, a developer duplicates part of the source code. The developer can then safely make changes to that part of the code without affecting the rest of the project. – Then, once the developer gets his or her part of the code working properly, he or she can Merge that code back into the main source code to make it official. – All of these changes are then tracked and can be reverted if need be. 3
  • 4. Git • Git is a specific open-source version control system created by Linus Torvalds in 2005. • Git is a distributed version control system, which means that the entire codebase and history is available on every developer’s computer, which allows for easy branching and merging. 4
  • 5. Create Github Account • With a personal account on GitHub, you can import or create repositories, collaborate with others, and connect with the GitHub community. • To create a personal Github account: 1. Navigate to https://github.com/ and follow the prompts. 2. Create a strong and unique password. 3. Choose GitHub Free account 4. verify your email address 5. Configure two-factor authentication 6. View your GitHub profile and dashboard 5
  • 6. Git Bash • Git Bash is an application for Microsoft Windows environments which enables you to interact with Github using a command line called “Bash”. • Git Bash is a package that installs Bash, some common bash utilities, and Git on a Windows operating system. • You can download it from: https://git- scm.com/downloads 6
  • 7. Git for Desktop • GitHub Desktop is an application that enables you to interact with GitHub using a GUI instead of the command line or a web browser. • You can use GitHub Desktop to complete most Git commands from your desktop with visual confirmation of changes. • You can push to, pull from, and clone remote repositories with GitHub Desktop, and use collaborative tools. • Go to https://desktop.github.com/, download and install it. 7
  • 8. Git Commands - git version: to check the version of the Git installed on your machine. - git init to initiate a local repository of the project. - git status to show modified files in working directory, staged for your next commit (the red files and folders are not committed to the repo). 8
  • 9. Git Commands • git add <filename> : to add the files to the staged area. • git add *: to add all files. • Now if we make a little change in any file and save it and type checked the status again, we can see the modified files with red so add them again by (git add . ). 9
  • 10. Git Commands • To upload your project to GitHub, First u need to authenticate yourself to Git bash/desktop • Git config--global user.name "user-name“ • Git config--global user.email mail@gmail.com • Git commit –m “first Commit” • Now your project ready to be uploaded to the remote repository • Go to the remote repository and get the link • Then, we need to link the local repo to the remote repo, using this command: • git remote add origin https://github.com/testname/repoName.git • git push -u origin master: To push the project to the remote repository. 10
  • 11. Git Commands • Now Go To the branch that we have created, and we can see all files of our test program uploaded successfully. • git clone https:// github.com/testname/repoName.git : to clone the repo to our local device to work with it this called (clone it). • git checkout –b name: To make another branch 11
  • 12. File Handling in C++ • File are used to store data in a relatively permanent form (e.g., on Hard disk, or other form of secondary storage). • Files can hold huge amounts of data if need. • For achieving file handling, we need to follow the following steps: • Create a Handler Object • Naming a file • Opening a file • Writing data into the file • Reading data from the file • Closing a file. 12
  • 13. Streams in C++ • We give input to the executing program and the execution program gives back the output. • Streams: the flow of data in a sequence of bytes. • The input and output operation between the executing program and files are known as “disk I/O operation”. 13
  • 14. Classes for File stream operations • Ofstream (output file stream): – is used to create files and to write information to files. – It can be accessed with the insertion operator ”<<“. – It contains open() function with default output mode. – Use the functions put() and write(). • ifstream (input file stream): – is used to read information from files. – It can be accessed with the extraction operator ”>>”. – It contains open() function with default input mode. – Use the functions get(), getline(), and read() • Fstream – This class provides support input and output operations. – Use functions from istream and ostream classes 14
  • 15. 15
  • 16. 16
  • 17. Create file and write text • #include <iostream> • #include <fstream> • using namespace std; • int main () { • ofstream myfile; • myfile.open ("example.txt"); • myfile << “Hello world.n"; • myfile.close(); • return 0; • } 17
  • 18. Reading a text file • #include <iostream> • #include <fstream> • #include <string> • using namespace std; • int main () { • string line; • fstream myfile ("example.txt"); • if (myfile.is_open()) { • while ( getline (myfile,line) ) { • cout << line << 'n'; } • myfile.close(); } • else cout << "Unable to open file"; • return 0; • } 18
  • 19. Writing on a text file using is_open() • #include <iostream> • #include <fstream> • using namespace std; • int main () { • ofstream myfile ("example.txt"); • if (myfile.is_open()) { • myfile << "This is a line.n"; • myfile << "This is another line.n"; • myfile.close(); } • else cout << "Unable to open file"; • return 0; • } 19
  • 20. Writing on a text file • #include <iostream> • #include <fstream> • #include <string> • using namespace std; • int main(){ • ofstream fout("test.txt"); • if (!fout.is_open()) • cout << "File can not be opennedn"; • else fout << "Cairo, Damietta, Assiut, Aswan"<<endl; • fout.close(); • return 0; • } 20
  • 21. Read lines of text file • #include <iostream> • #include <fstream> • #include <string> • using namespace std; • int main(){ • ifstream f2; • string line; • int count = 0; • f2.open("example.txt"); • while (getline(f2, line)) { • cout << line << endl; • count++; } //end while • cout << "count of lines = " << count << endl; • f2.close(); • } //end main 21
  • 22. Writing then Reading from a Text File using an Array of String • int main(){ • char cities[200] = "Cairo, Damietta, Assiut, Aswan."; • fstream f1; • f1.open("section.txt", ios::out); //Open for writing • if (!f1) { cout << "file can not foundn"; } • else { • for (int i = 0; i < strlen(cities); i++){ • f1.put(cities[i]); } } • f1.close(); • fstream f2; • string res = ""; • f2.open("section.txt", ios::in); //Open for reading • if (!f2) { cout << "file can not foundn"; } • else { • while(!f2.eof()) { • res += f2.get();}} • cout << res << endl; • f2.close(); • return 0; • } 22