File flow operation TELLG (), seekg ()

xiaoxiao2021-03-05  25

TELLG () - Returns an INT type value that represents the current location of the "Built-in Metrics". This function is only valid when you read a file. For example: #include void main () {// If we have already in Test_File.txt, "Hello" content ifstream file ("Test_File.txt"); char Arr [10]; file. READ (Arr, 10); // Since Hello accounts for 5 words, this will return 5 cout << file.tellg () << endl; file.close ();} tellp () - with tellg () There is the same function, but it is used to write files. All in all: When we read a file, and to know the current location of the built-in indicator, we should use TELLG (); when we write a file, you should use Tellp (). Because of this The usage of the function is exactly the same as TELLG (), I will not give an example code. Seekp () - Remember seekg ()? When I read a file and want to reach a particular location in the file, I have used it. Seekp () is also true, but it is used to write a file. For example, if I read and write in the file, and to locate the three characters of the current location, you need to call FileHandle.seekg (-3). But if I write a file, and, for example, I want to rewrite After the content of the next 5 characters, I must go back to 5 words, so I should use FileHandle.seekp (-5). Ignore () - is used to read the file. If you want to skip a certain number of characters, just use this function. In fact, you can also use Seekg () instead, however, using ignore () has an advantage - you can specify a specific "Delimiter Rule", which makes ignore () stop at the specified location. The function prototype is as follows: iStream & Ignore (int Ncount, Delimiter); Ncount indicates the number of characters to be skipped, and Delimiter - With its label: If you want to stop at the end of the file, you can use the EOF value In this way, this function is equivalent to seekg (); however, this parameter can also use other values, such as '/ n', which can be positioned at the new row while the wrap. The following is an example: #include void main () {// Assume "Hello World" in Test_File.txt ifstream File ("Test_File.txt"); Static Char Arr [

转载请注明原文地址:https://www.9cbs.com/read-34997.html

New Post(0)