Over the past few days I have been searching literally everywhere for an answer to this question: How do you output a stings contents into a char*? I am creating a username/password system were you can register yourself, or log into an account you have already registered. In the main program I have it copy the username and password onto a txt file when you register. If you log in, it searches for your username throughout the txt file and finds the next line (the password). Then it compares what you put in as your password and what your registered password is. I created this short program just testing how to find the line after a certain word. Then i realized I need to have it use a string instead of a random word in parenthesis. Here is the short program that pulls the line following what you search for. Sorry if code is messy. :(
Yanson, I tried the string copy method and all went well until I got to the part of the program where it puts the sting into the char*. The moment you type in the username and click enter it asks to close the program due to errors. Here is the code I used:
Maybe I'm stupid but aren't you trying to put a square peg in a round hole? Or is the string one character long? If so then just use type casting/conversion and do
char mychar;
string mystring;
mychar = mystring;
The data will be copied and the remainder (if any) will be lost, if I am not mistaken.
I didn't read your code so I apologize if this answer is useless.
Cire, I don't know how that would work, that is why I constructed the program the way I did. If you know how to do that, I would appreciate it if you posted a program that does what I am trying to accomplish.
Try just making search a string instead of a char*. It looks like your program would still work with the change. If there are errors afterwards, try to figure them out or post them.