On line 18, I'd like this file to save in a folder in the same directory called "Usernames". Because I'm using c_str(), it will create a str file instead of a .txt file. How do I save this file to that folder?
Also I'm trying to make a method to scan a file for a keyword.
In this file will be a username and password. The line that contains the password precedes the username.
I'm thinking the code will look something like this but I need help.
Will annotate code below...
On line 2, how do I define the length of myfile according to the amount of lines it has?
On line 5, how to I take that line and convert it into a char array to test if it is the line that contains the password?
On line 8, is this the correct way to change the line?
None of this code has been written into an IDE yet because it's just my brainstorming in my notebook. Hoping for some feedback.
On line 2, how do I define the length of myfile according to the amount of lines it has?
You can't know how many lines there are unless you scan the whole file first, but maybe you don't need to know the number of lines. You could use line 1 as a loop condition and it will stop the loop when getline fails to read a line (at the end of the file).
while(getline(myfile, line))
Tenom722 wrote:
On line 5, how to I take that line and convert it into a char array to test if it is the line that contains the password?
Why do you need to convert it into an array? Just use the line variable.
if(line == "password")
Tenom722 wrote:
On line 8, is this the correct way to change the line?
Not sure what you are trying to do here. Changing the line variable will not change the file content. If you want to read the next line and run the loop again I think you should just remove the else part and the goto statement and let the loop condition read in the next line (see my recommendation for line 2 above).
I need to convert it into an array because I only need part of the line that starts with password: the rest of the line after "password: " that actually contains the password.