Question:
invalid conversion const char to const char in c++?
TV
2009-09-29 21:31:24 UTC
heres a pseudocode
void run(const char c){
...
ifstream f (c);//error
...
}
int main(){
run("list.dat");
}
i get the invalid conversion every time. im new to c++.
Three answers:
2009-09-29 21:56:07 UTC
I agree. Look up "C style strings" and you will see the problem.
2016-04-05 05:24:41 UTC
There isn't realy a decimal type, there are classes that give what seems to be decimal, but these are not realy standard. The type mybe int double float char* Microsoft do a 'Decimal' class that can be used as if a double or float, it is very much slower implementation than 'float', this is because it is not a format that is compatible with the maths processor in your computer's CPU, it is a software implementation. Decimal is more accurate though, so if running time isn;t a problem it can give more accurate results. You need to remember though that not all C++ (and derived languages) will have the Decimal class, and if they do they may not implement it in the same way, in fact you will find some are realy floats under a different name (like the 'Currency' type often is). So your decimal will not fit into a char, decimal is a 128bit value, your char is 8bit. I just had a look, the link to the Decimal class is below, it does have a ToByte and ToSByte (signed), but it looks very dodgy to me, make sure that you wrap these in the try-catch as in the example and keep an eye on those exceptions for your number ranges.
2009-09-29 21:53:59 UTC
const char c is a char that is const



ifstream argument must be a

const char *


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...