🗊 Презентация CSC2430 File I/O part 2

Нажмите для полного просмотра!
CSC2430 File I/O part 2, слайд №1 CSC2430 File I/O part 2, слайд №2 CSC2430 File I/O part 2, слайд №3 CSC2430 File I/O part 2, слайд №4 CSC2430 File I/O part 2, слайд №5 CSC2430 File I/O part 2, слайд №6 CSC2430 File I/O part 2, слайд №7 CSC2430 File I/O part 2, слайд №8 CSC2430 File I/O part 2, слайд №9 CSC2430 File I/O part 2, слайд №10 CSC2430 File I/O part 2, слайд №11 CSC2430 File I/O part 2, слайд №12 CSC2430 File I/O part 2, слайд №13 CSC2430 File I/O part 2, слайд №14 CSC2430 File I/O part 2, слайд №15 CSC2430 File I/O part 2, слайд №16 CSC2430 File I/O part 2, слайд №17 CSC2430 File I/O part 2, слайд №18

Вы можете ознакомиться и скачать презентацию на тему CSC2430 File I/O part 2. Доклад-сообщение содержит 18 слайдов. Презентации для любого класса можно скачать бесплатно. Если материал и наш сайт презентаций Mypresentation Вам понравились – поделитесь им с друзьями с помощью социальных кнопок и добавьте в закладки в своем браузере.

Слайды и текст этой презентации


Слайд 1


CSC2430 File I/O part 2
Описание слайда:
CSC2430 File I/O part 2

Слайд 2


Review: File I/O Header file: #include Declaring variables You declare a variable of type ifstream for reading or of type ofstream for writing...
Описание слайда:
Review: File I/O Header file: #include Declaring variables You declare a variable of type ifstream for reading or of type ofstream for writing Associating your file with the variable: You need to either specify the filename in the constructor, or use the open method to make the association Reading from or writing to file Works nearly the same as console I/O Disassociating your file with the variable: If you specified the filename in the constructor let the destructor close it. If you used the open method, then call close method when you are done with the file

Слайд 3


Streams as parameters Streams are ALWAYS pass-by-reference (&) Example: Function to open files: void openOutputFile (ofstream& fout) { string name;...
Описание слайда:
Streams as parameters Streams are ALWAYS pass-by-reference (&) Example: Function to open files: void openOutputFile (ofstream& fout) { string name; cout

Слайд 4


Example: writing a line of text
Описание слайда:
Example: writing a line of text

Слайд 5


Example: reading a line of text
Описание слайда:
Example: reading a line of text

Слайд 6


What can do with your stream?
Описание слайда:
What can do with your stream?

Слайд 7


Reading through a file Read through the file with getline can be done with simple loop while (getline(fin, line)) cout When using >> to read through...
Описание слайда:
Reading through a file Read through the file with getline can be done with simple loop while (getline(fin, line)) cout When using >> to read through a file, you might want to do an initial read before starting loop to “prime” the read fin >> data; while(!fin.eof()) { cout data; } This assumes that the last line of file ends with ‘\n’. What happens if that’s not the case?

Слайд 8


Your turn… Pair up with your neighbor to write this function: Write this function called skipWhite that reads past any “space” character until the...
Описание слайда:
Your turn… Pair up with your neighbor to write this function: Write this function called skipWhite that reads past any “space” character until the next character to be read is some other character or EOF Recall that your parameter MUST be a reference parameter You will want to use fin.peek(); Use the isspace(ch)function in You can call fin.ignore() with no parameters and it will simply read & discard the next character (so long as you are not at EOF) 2) Revise the following code to use skipWhite function so it works no matter whether or not your file ends with ‘\n’. Expect to do a total rewrite of the logic! fin >> data; while(!fin.eof()) { cout data; }

Слайд 9


Solution to exercise
Описание слайда:
Solution to exercise

Слайд 10


Solution to exercise
Описание слайда:
Solution to exercise

Слайд 11


Can you mix getline and >>?
Описание слайда:
Can you mix getline and >>?

Слайд 12


ifstream fin; string str, line; fin.open("afile.txt"); getline(fin, line); fin >> str; cout
Описание слайда:
ifstream fin; string str, line; fin.open("afile.txt"); getline(fin, line); fin >> str; cout

Слайд 13


Behind the scenes with ofstream By default, what you write to an ofstream is first saved up in a “buffer” (block of memory). Write is delayed until...
Описание слайда:
Behind the scenes with ofstream By default, what you write to an ofstream is first saved up in a “buffer” (block of memory). Write is delayed until buffer is full, you call “flush”, or file is closed. Why is this done? Better performance! What do you think your file would contain if your program crashes before all the data is flushed to disk?

Слайд 14


Behind the scenes with ifstream
Описание слайда:
Behind the scenes with ifstream

Слайд 15


Behind the scenes with ifstream An ifstream object reads a whole block of data from the file into an in memory “buffer”
Описание слайда:
Behind the scenes with ifstream An ifstream object reads a whole block of data from the file into an in memory “buffer”

Слайд 16


Behind the scenes with ifstream An ifstream object reads a whole block of data from the file into an in memory “buffer” getline() call copies...
Описание слайда:
Behind the scenes with ifstream An ifstream object reads a whole block of data from the file into an in memory “buffer” getline() call copies characters from the buffer until sees end of line (‘\n’) into the “line” variable. Pointer to start of “unread” text is advanced Note: “’\n’ is not copied into “line”

Слайд 17


What about wide characters? Use wifstream and wofstream instead…
Описание слайда:
What about wide characters? Use wifstream and wofstream instead…

Слайд 18


CSC2430 File I/O part 2, слайд №18
Описание слайда:



Теги CSC2430 File part
Похожие презентации
Mypresentation.ru
Загрузить презентацию