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

На нашем сайте вы можете скачать и просмотреть онлайн доклад-презентацию на тему CSC2430 File I/O part 2 абсолютно бесплатно. Урок-презентация на эту тему содержит всего 18 слайдов. Все материалы созданы в программе PowerPoint и имеют формат ppt или же pptx. Материалы и темы для презентаций взяты из открытых источников и загружены их авторами, за качество и достоверность информации в них администрация сайта не отвечает, все права принадлежат их создателям. Если вы нашли то, что искали, отблагодарите авторов - поделитесь ссылкой в социальных сетях, а наш сайт добавьте в закладки.



Оцените!
Оцените презентацию от 1 до 5 баллов!
  • Тип файла:
    ppt / pptx (powerpoint)
  • Всего слайдов:
    18 слайдов
  • Для класса:
    1,2,3,4,5,6,7,8,9,10,11
  • Размер файла:
    142.73 kB
  • Просмотров:
    57
  • Скачиваний:
    0
  • Автор:
    неизвестен



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

№1 слайд
CSC File I O part
Содержание слайда: CSC2430 File I/O part 2

№2 слайд
Review File I O Header file
Содержание слайда: Review: File I/O Header file: #include <fstream> 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
Содержание слайда: Streams as parameters Streams are ALWAYS pass-by-reference (&) Example: Function to open files: void openOutputFile (ofstream& fout) { string name; cout << "Enter the name of the file (complete path): "; getline (cin, name); fout.open(name); if (fout.fail()) { cout << "Cannot open ‘” << name << “’\n"; exit (1); } }

№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
Содержание слайда: Reading through a file Read through the file with getline can be done with simple loop while (getline(fin, line)) cout << line << endl; //do something with data But if you have multiple data items per line or numeric data to read, you will want to use >> 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 << endl; //do something with data fin >> 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
Содержание слайда: 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 <cctype> 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 << endl; //do something with data fin >> data; }

№9 слайд
Solution to exercise
Содержание слайда: Solution to exercise

№10 слайд
Solution to exercise
Содержание слайда: Solution to exercise

№11 слайд
Can you mix getline and gt gt
Содержание слайда: Can you mix getline and >>?

№12 слайд
ifstream fin string str, line
Содержание слайда: ifstream fin; string str, line; fin.open("afile.txt"); getline(fin, line); fin >> str; cout << "line = " << line << endl; cout << "str = " << str << endl; fin.close(); fin.open("afile.txt"); fin >> str; getline(fin, line); cout << "line = " << line << endl; cout << "str = " << str << endl; fin.close();

№13 слайд
Behind the scenes with
Содержание слайда: 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
Содержание слайда: Behind the scenes with ifstream

№15 слайд
Behind the scenes with
Содержание слайда: 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
Содержание слайда: 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?
Содержание слайда: What about wide characters? Use wifstream and wofstream instead…

№18 слайд
https github.com arias-spu
Содержание слайда: https://github.com/arias-spu/CSC-CPP-Examples

Скачать все slide презентации CSC2430 File I/O part 2 одним архивом: