-
I think it works, I did it once when I first started working, and I don't remember it very well, but you can try it with the seek function, locate it first, read it later, and I remember when I was doing this, I read the book The C Programmer, which is about 234 pages.
-
Directly save the number of rows to be fetched and the number of the first few rows to memory (number of rows and getline).
You don't have to read the rest, so you can read less memory.
-
With the getline function, read each one from the file stream, then and"Language scores"If the string matches, it is added to the vector, and then all of it is read, and then sorted. Do you understand that? I don't understand, I'll write it for you.
-
This course focuses on the application of reading and writing files and some member functions in string classes. #include #include
#include
#include
#include
using namespace std;int main()string strsearch;
cout<<"please enter the searchitem:";
cin>>strsearch;
string strline;
while (getline(ifile,strline))}int j=0;
string strtemp=str[0];
for (j=0;j:";
char c;
cin>>c;
if (c=='n')
return 0;
You write the information in a document called a document in your project. Just finished knocking. If you need a source, leave your mailbox.
-
#include
char buf[512];
int main()
Redirect input stream command line: prog <
-
This can be done using the C++ library function GetLine.
GetLine generates a string containing a string of characters read from the input stream until the following happens to cause this string to end.
1) Read the end of the file;
2) encounters the terminator specified by the function;
3) Input to the maximum.
There are two types of overloads for getline:
Parameter description: buffer: The read data will be stored in the buffer.
num: A maximum of num characters can be read. That is, the maximum amount mentioned earlier.
delim: Terminator, which will end the input when the specified terminator is encountered. In the first type of overload, the ending character is, that is, the end of the line break is encountered.
So to implement the whole line read, you can use the first overload. An example is as follows:
#include
using namespace std;
int main()
char buf[1024];Stored BUFF.
while(getline(buf,sizeof(buf))).
cout <<"read line:" <
-
Unfortunately, it is impossible for a computer to read the nth line of a txt file with a time complexity of o(1).
To read row n-1 must be found => row n-2 must be found ....Row 1 must be found. Therefore, reading the string of the 5000th line can only be found line by line, just like a human reading a book, to see the 5000th paragraph (the 5000th line of txt is actually printed out as the 5000th paragraph) must be counted paragraph by paragraph, otherwise it can only be estimated, and it is not accurate.
If you want to locate the nth "row" or the nth record with o(1) time complexity, you must use "index storage", "hash storage", etc., such as database files. For specific details, you can learn "Data Structure", "Database Principles", etc.
#include
Read the filename file (path), line whichline+1 text.
char * readspeacialline(char *filename, int whichline)
while (!feof(fp))
fgets(strline, 1024, fp);Read one row and navigate to the next row.
currentline++;
fclose(fp);Close the file.
return null;
int main()
-
#include
#define maxc 1024
int readspeacialline(int i)while (1)
elsewhile (1) }
end:fclose(fp);Close the file.
return ret;
Using the fgets function, fgets is read one row at a time.
Use memset to clear the strline to prevent the content in the last strline from not being cleared.
-
Sit back and wait, there shouldn't be a better way to locate how many lines there are, unless the file is loaded in the first place.
Let's give you a method.,This method is set up.,You can change it to read.,If you can read the configuration, it's no problem, right? >>>More
Don't understand what you mean by startmark and enterstumark. >>>More
You save the path in an XML and read it out the next time you start it.
textreader reader;
int linecount = 0; >>>More
The drop-down box contains multiple items, and the text that can read one of the items in the drop-down box (n represents the index). >>>More