Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I need to read just 1 specific line from a text file using c++. The file doesn't change it's content, the lines are always the same. I need to be able to read line 37 for example, without having to read the previous 36 lines. Is this even possible?
If you know the count of characters preceeding line 37 use std::istream::seekg() to set the file pointer to the begin of line 37 and use std::getline() to read it.
OTOH, if said file never changes there is no need to read it at all. Just define the string in your code.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I've designed a program that can encrypt 26 English letters.
Here's how I'm handling the input. I'm reading it from a text file and stores it in a string.
ifstream L;
string str1;
char ch;
L.open("ToBeCoded.txt");
while(iL.get(ch))
str1.push_back(ch);
However, it's inefficient, if I want to read a different file, I have to change the name in codes to make it work.
So is there any dynamic way to do so? Like drag the file or type the address of the file during run time?
By the way, do you have a better way to read txt to string? This one 'seems' slow.
you can use istream getline instead
http://www.cplusplus.com/reference/istream/istream/getline/
I would suggest you use the getline for this kind of problem.
http://www.cplusplus.com/reference/string/string/getline/?kw=getline
getline is an ifstream function that will get the string user efficiently.
If you wanted to get the whole string file, just go to the link that Neil Kirk posted:
Read whole ASCII file into C++ std::string
it explains exactly how to do that.
If you are on Windows you can use DragAcceptFiles and WM_DROPFILES messages. More details here:
http://msdn.microsoft.com/en-us/library/bb776406(VS.85).aspx
http://msdn.microsoft.com/en-us/library/bb774303(VS.85).aspx
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a file like:
a [able%5:00:00:capable:00] [able] capable
a [abnormal%3:00:00::] [abnormal]
a [absent%3:00:00::] [absent]
a [absolute%3:00:00::] [absolute] perfect or complete
a [abstract%3:00:00::] [abstract] existing only in the mind
a [abundant%3:00:00::] [abundant] plentiful
I want to get first column "avle", "abnormal" etc to my object. How to crop them and how storage them?
Use the string tokenizer, the best/easiest way to split a line into different variables.
char* word = strtok(line," [%:]");
char* word2 = strtok(0," [%:]");
int value = strtoi(strtok(0," [%:]"));
to store there is a vector container, but there can be used any type of arrays, what is more convenient
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I need to compare 5 files by their file paths: a,b,c,d,e and find duplicates if exists.
How can I do this in c++ via md5sum comparison of files?
You'd need to compute a checksum for each file (write it yourself or call an external program), get hold of each file, ... This depends on the operating system. It is much easier to do something like this in a scripting language.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I need to do a program in C/C++ in witch one i'll need to take each sction of a PE File, hash them and sign them, I made yet the hashing and signing functions but:
I don't know how to get each section of a PE File as a char* or byte*,
I don't know how to if i can use a simple fstream and search to a n byte,
and after that how to add a new section .sig to the PE File with my signature table.
Thanks for help
Download the documentation here:
Microsoft PE and COFF Specification
Sample code from CodeProject: Parse a PE
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have seen lot of tutorials and documentation on how to get the files descriptors from a given pid. Well, I want to do otherwise.
Thanks.
Of course not, that's like trying to get the PID that called main. Every process has a file descriptor 0 (stdin), 1, 2, etc., and they mean different things for each process.
A file descriptor, which is just a small integer, isn't meaningful unless you already know what process you are talking about.