-
char[255] to string?
How would I do something like this:
Code:
char en_file1[255];
int file1_len;
ifstream getFileName ("aFile.ini");
getFileName.getline(en_file1,255,'\n');
file1_len = strlen(en_file1);
for (int i = 0; i < file1_len; i++)
{
de_file1[i] = en_file1[i];
}
This compiles without any errors/warnings BUT when I run it, it says the program has had an error and will now close...
basically I need somthing that will convert a character[255] to a string.
-
There seems to be no reason at all for you to even worry about this. Just use a std::string and forget about it, don't even convert.
-
well, I think i forgot to mention some things.
1. I am using this program to decrypt/encrypt files...
2. getFileName.getline... requires a character array to work, strings return an error while compiling
3. i wrote a function that encrypts/decrypts these files but only uses strings [encrypt(string, string string&);]
im in quite a bit of a issue here :(
-
There should be an implicit conversion if you pass a char array to a function that expects a std::string. That said, you can use the non-member getline function instead:
Code:
std::string en_file1;
getline(getFileName,en_file1,'\n');