SlideShare uma empresa Scribd logo
1 de 6
Reading in from a file 
Author – Andrew Madden
Second Project 
This program will read eight numbers from a text file, it 
will then ask the user how many containers will be on 
the ship and then determine if the ship is safe or 
whether it is to heavy.
Declaring and opening file 
Firstly a text file needs to be 
created in the same source file as 
the C++ code. As you can see to 
the left I made a text file called 
input.txt 
This code declares the file as a 
variable. Then it opens the file so the 
project can access its context.
Inside the text file 
This is what is inside the text file. Each 
number represents a variable and is the 
variable is given that value
How to read in from a file 
It acts in the same way as the CIN function where the 
file(variable) gives cargo1 the first value which is inside the 
input.txt file.
Result 
This shows that the length, width and height of the cargo is 
automatically assigned and there is no need for any user input.

Mais conteúdo relacionado

Destaque (11)

Prueba 2 bloque ingles 12345lalalalañdñ.fg
Prueba 2 bloque ingles 12345lalalalañdñ.fgPrueba 2 bloque ingles 12345lalalalañdñ.fg
Prueba 2 bloque ingles 12345lalalalañdñ.fg
 
Istoria internet
Istoria internetIstoria internet
Istoria internet
 
บทที่6
บทที่6บทที่6
บทที่6
 
White Paper Nextbike UK 250
White Paper Nextbike UK 250White Paper Nextbike UK 250
White Paper Nextbike UK 250
 
Evaluation question 3
Evaluation question 3Evaluation question 3
Evaluation question 3
 
ICRM2013_4_26
ICRM2013_4_26ICRM2013_4_26
ICRM2013_4_26
 
MS. POWER POINT 2007 BAB 6 KELAS IX
MS. POWER POINT 2007 BAB 6 KELAS IX MS. POWER POINT 2007 BAB 6 KELAS IX
MS. POWER POINT 2007 BAB 6 KELAS IX
 
งานอาเมเมเมเ
งานอาเมเมเมเงานอาเมเมเมเ
งานอาเมเมเมเ
 
Jd
JdJd
Jd
 
Микроразметка - улучшения связи сайта с пользователями и роботами
Микроразметка - улучшения связи сайта с пользователями и роботамиМикроразметка - улучшения связи сайта с пользователями и роботами
Микроразметка - улучшения связи сайта с пользователями и роботами
 
안철수의 공정성장론 20150407
안철수의 공정성장론 20150407안철수의 공정성장론 20150407
안철수의 공정성장론 20150407
 

Semelhante a C2

Assignment- C++ Write a program that reads a text file using binary mo.docx
Assignment- C++ Write a program that reads a text file using binary mo.docxAssignment- C++ Write a program that reads a text file using binary mo.docx
Assignment- C++ Write a program that reads a text file using binary mo.docx
bickerstaffinell
 
Csc1100 lecture15 ch09
Csc1100 lecture15 ch09Csc1100 lecture15 ch09
Csc1100 lecture15 ch09
IIUM
 
C++ - UNIT_-_V.pptx which contains details about File Concepts
C++  - UNIT_-_V.pptx which contains details about File ConceptsC++  - UNIT_-_V.pptx which contains details about File Concepts
C++ - UNIT_-_V.pptx which contains details about File Concepts
ANUSUYA S
 

Semelhante a C2 (20)

Python reading and writing files
Python reading and writing filesPython reading and writing files
Python reading and writing files
 
Assignment- C++ Write a program that reads a text file using binary mo.docx
Assignment- C++ Write a program that reads a text file using binary mo.docxAssignment- C++ Write a program that reads a text file using binary mo.docx
Assignment- C++ Write a program that reads a text file using binary mo.docx
 
Chapter10
Chapter10Chapter10
Chapter10
 
(130316) #fitalk bit torrent protocol
(130316) #fitalk   bit torrent protocol(130316) #fitalk   bit torrent protocol
(130316) #fitalk bit torrent protocol
 
chapter-12-data-file-handling.pdf
chapter-12-data-file-handling.pdfchapter-12-data-file-handling.pdf
chapter-12-data-file-handling.pdf
 
Input and output in c++
Input and output in c++Input and output in c++
Input and output in c++
 
Chapter - 5.pptx
Chapter - 5.pptxChapter - 5.pptx
Chapter - 5.pptx
 
I x scripting
I x scriptingI x scripting
I x scripting
 
Example esb file-to-string flow
Example esb file-to-string flowExample esb file-to-string flow
Example esb file-to-string flow
 
Csc1100 lecture15 ch09
Csc1100 lecture15 ch09Csc1100 lecture15 ch09
Csc1100 lecture15 ch09
 
An Efficient Search Engine for Searching Desired File
An Efficient Search Engine for Searching Desired FileAn Efficient Search Engine for Searching Desired File
An Efficient Search Engine for Searching Desired File
 
Advanced programming ch2
Advanced programming ch2Advanced programming ch2
Advanced programming ch2
 
XML Tutor maXbox starter27
XML Tutor maXbox starter27XML Tutor maXbox starter27
XML Tutor maXbox starter27
 
Bt0082 visual basic
Bt0082 visual basicBt0082 visual basic
Bt0082 visual basic
 
Data file handling
Data file handlingData file handling
Data file handling
 
File handling3.pdf
File handling3.pdfFile handling3.pdf
File handling3.pdf
 
File handling4.pdf
File handling4.pdfFile handling4.pdf
File handling4.pdf
 
C++ - UNIT_-_V.pptx which contains details about File Concepts
C++  - UNIT_-_V.pptx which contains details about File ConceptsC++  - UNIT_-_V.pptx which contains details about File Concepts
C++ - UNIT_-_V.pptx which contains details about File Concepts
 
Module2-Files.pdf
Module2-Files.pdfModule2-Files.pdf
Module2-Files.pdf
 
BCSL 056 solved assignment
BCSL 056 solved assignmentBCSL 056 solved assignment
BCSL 056 solved assignment
 

Último

Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
amilabibi1
 
Uncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoUncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac Folorunso
Kayode Fayemi
 
If this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New NigeriaIf this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New Nigeria
Kayode Fayemi
 
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
David Celestin
 
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptxChiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
raffaeleoman
 

Último (15)

lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.
 
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
 
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdf
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdfSOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdf
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdf
 
Digital collaboration with Microsoft 365 as extension of Drupal
Digital collaboration with Microsoft 365 as extension of DrupalDigital collaboration with Microsoft 365 as extension of Drupal
Digital collaboration with Microsoft 365 as extension of Drupal
 
Uncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoUncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac Folorunso
 
If this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New NigeriaIf this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New Nigeria
 
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdfThe workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
 
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
 
Dreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio IIIDreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio III
 
My Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle BaileyMy Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle Bailey
 
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptxChiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
 
Dreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video TreatmentDreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video Treatment
 
ICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdfICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdf
 
Report Writing Webinar Training
Report Writing Webinar TrainingReport Writing Webinar Training
Report Writing Webinar Training
 
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdfAWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
 

C2

  • 1. Reading in from a file Author – Andrew Madden
  • 2. Second Project This program will read eight numbers from a text file, it will then ask the user how many containers will be on the ship and then determine if the ship is safe or whether it is to heavy.
  • 3. Declaring and opening file Firstly a text file needs to be created in the same source file as the C++ code. As you can see to the left I made a text file called input.txt This code declares the file as a variable. Then it opens the file so the project can access its context.
  • 4. Inside the text file This is what is inside the text file. Each number represents a variable and is the variable is given that value
  • 5. How to read in from a file It acts in the same way as the CIN function where the file(variable) gives cargo1 the first value which is inside the input.txt file.
  • 6. Result This shows that the length, width and height of the cargo is automatically assigned and there is no need for any user input.