Login Register






Char query filter_list
Author
Message
Char query #1
I have this function,

Code:
void load_dict(char filename[15]) { std::ifstream dict; //Load Dictionary dict.open(filename); char test[25]; //Character Limit for(int i = 0; i < count_file(filename); i++) { dict >> test; std::cout << test; } }

Now If the function is like:

Code:
void load_dict(std::string filename) { std::ifstream dict; //Load Dictionary dict.open(filename); char test[25]; //Character Limit for(int i = 0; i < count_file(filename); i++) { dict >> test; std::cout << test; } }

I can't compile, I get a debug error, When I use std:Confusedtring instead of char, to be precise! Why is that so? Why I have to use char, can't I use string to achieve this? Can any one shed some light on that..
My Blog: http://www.procurity.wordpress.com
Donations: 1HLjiSbnWMpeQU46eUVCrYdbkrtduX7snG

Reply

Char query #2
I have this function,

Code:
void load_dict(char filename[15]) { std::ifstream dict; //Load Dictionary dict.open(filename); char test[25]; //Character Limit for(int i = 0; i < count_file(filename); i++) { dict >> test; std::cout << test; } }

Now If the function is like:

Code:
void load_dict(std::string filename) { std::ifstream dict; //Load Dictionary dict.open(filename); char test[25]; //Character Limit for(int i = 0; i < count_file(filename); i++) { dict >> test; std::cout << test; } }

I can't compile, I get a debug error, When I use std:Confusedtring instead of char, to be precise! Why is that so? Why I have to use char, can't I use string to achieve this? Can any one shed some light on that..
My Blog: http://www.procurity.wordpress.com
Donations: 1HLjiSbnWMpeQU46eUVCrYdbkrtduX7snG

Reply

RE: Char query #3
you can use std:Confusedtring by using the function .c_str() which returns the string as a const * char.
so
Code:
filename.c_str()

Reply

RE: Char query #4
you can use std:Confusedtring by using the function .c_str() which returns the string as a const * char.
so
Code:
filename.c_str()

Reply

RE: Char query #5
(02-16-2014, 05:27 PM)mrpassword Wrote: you can use std:Confusedtring by using the function .c_str() which returns the string as a const * char.
so
Code:
filename.c_str()

Yes, the standard streams doesn't accept a standard string, so use c-string as @mrpassword said!

Thanks
[Image: wvBFmA5.png]

Reply

RE: Char query #6
(02-16-2014, 05:27 PM)mrpassword Wrote: you can use std:Confusedtring by using the function .c_str() which returns the string as a const * char.
so
Code:
filename.c_str()

Yes, the standard streams doesn't accept a standard string, so use c-string as @mrpassword said!

Thanks
[Image: wvBFmA5.png]

Reply