|
Following code works perfectly fine .
String^ input = Console::ReadLine();
double amount = Convert::ToDouble(input);
Prasad
MS MVP - VC++
|
|
|
|
|
|
Sorry I'm a real beginner in c++. I have tried the above method but it returns a lot of errors when I try to compile it. I am sure I am missing something.
Of note, I am using Win32 Application in Visual Studio 2005.
Could you please make an example with a very simple code that I can compile so that I can understand what I am doing wrong.
Thank you.
|
|
|
|
|
J_E_D_I wrote: Of note, I am using Win32 Application in Visual Studio 2005.
In this case, you can use native functions like atof .
Original code in using managed C++. You need to use /clr option, from native code to use that.
Prasad
MS MVP - VC++
|
|
|
|
|
Thank you for the advice. I have tried to do so but somehow it doesn't work.
As you can see from the code below, my intention is for the program to read a number saved in an excel file (fileExcel) with the getline function and then convert this string to number in order to perform some mathematical operations on it. With the getline function I only manage to visualize this string on the console, but it doesn't seem to be "seen" by the atof command.
Any suggestion would be very welcome!
while<br />
<br />
(! fileExcel.eof()) <br />
{<br />
<br />
getline (fileExcel, stringa);<br />
<br />
double NUMstringa = atof (stringa);<br />
<br />
cout << NUMstringa;<br />
<br />
etc...
|
|
|
|
|
J_E_D_I wrote: cout << NUMstringa;
This displays the double as a string. If it displays the correct number then it's working.
If you put a breakpoint on that line, you should be able to look at the values of stringa and
NUMstringa. Are they valid?
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Thanks, that was a quick reply!!
No, it doens't display the number!
cout << stringa; works fine and displays the number saved on the excel file (but unfortunately as a string)
cout << NUMstringa; doesn't display anything! It doesn't acutally compile because it shows an error.
It says:
Error 1 error C2664: 'atof' : cannot convert parameter 1 from 'std::string' to 'const char *' c:\documents and settings\edy\my documents\my programs\csv\csv\csv.cpp 46
HELP!
|
|
|
|
|
My next question was going to be - What type is "stringa"?
Try
double NUMstringa = atof (stringa.c_str());
cout << NUMstringa;
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
You are a star, thank you so much!
It works perfectly and it solved a problem that kept me stuck for days.
What does adding the ".c_str()" command to the "atof" function exactly do?
Best wishes
|
|
|
|
|
J_E_D_I wrote: What does adding the ".c_str()" command to the "atof" function exactly do?
atof() takes a const char/wchar_t * as an argument.
To quote from the "basic_string::c_str()" docs:
"Converts the contents of a string as a C-style, null-terminated string."
So c_str() converts the string to a type usable by atof().
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
J_E_D_I wrote: cout << NUMstringa; doesn't display anything! It doesn't acutally compile because it shows an error.
Nice to see , that finally, you solved your problem.
But, some advice, while using forums.
Always, be very specifice while stating the problem. If, you had mentioned this (compiler error) line initially, that would have definitely saved some posts. .
Prasad
MS MVP - VC++
|
|
|
|
|
Hi,
Can any one give me some information on how to optimize performance while using both managed and unmanaged C++ calls in C++ /CLI
Regards
Sabarish
|
|
|
|
|
help me to know about the some of the keywords in C language they r
REGISTER,STATIC,UNION,SIGN AND UNSIGN
pls take out some time and try to give me with examples.
|
|
|
|
|
Let’s see:
1) auto -> modifier automatic (ignore)
2) break -> break out of loop or ‘switch – case’ construct
3) case -> part of ‘switch –case’ construct
4) char -> a signed single byte (8-bits) character (normally)
5) const -> a promise that you are not going to change the value of a variable
6) continue –> goto start of loop
7) default –> default case in ‘switch – case’ construct
8) do –> start of ‘do-while loop’ construct
9) double –> double precision numeric value
10) else –> ‘if – then – else’ construct
11) enum -> a grouping of int sized named constants
12) extern -> declaration of a named item is in external file (normally ignored)
13) for -> start of for loop ( for( i=0; i<n; ++i)="" do="" something="" )
14)="" goto="" -=""> goto named label (rarely used and only if absolutely required)
15) if -> test if true ( if( f != 0 ) do something )
16) int -> whole numeric value (no decimal point) (size of machine word in theory)
17) long -> whole numeric value (size ?)
18) register -> suggestion to compiler to place variable in register (normally ignored)
19) return -> return variable to calling function
20) short -> 16-bit integer (int) variable
21) signed -> (modifier) sign matters +/- (ignored, because it is default behavior)
22) sizeof -> size of variable (in C++ size of object, which is not the same thing)
23) static -> life time (exist in permanent memory)
24) struct -> a grouping of values or a record.
25) switch -> start of ‘switch – case’ construct
26) typedef -> method for giving a user defined type a name
27) union -> method of combining types (rarely used)
28) unsigned -> (modifier) all values are positive ( unsigned int )
29) void -> no return value, or no argument
30) volatile -> you can change value any time (stupid – ignore – default behavior)
31) while -> start of ‘while loop’, end of ‘do while loop’
Hmmm! I think that is all but I thought there where 32 keywords. Any way there are still 14 preprocessor keywords.
Oh – by the way, the keywords are case sensitive.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
thanks a lot for responding for my queries.
regards
rani
|
|
|
|
|
Remember to keep in mind that some keywords act differently in C++.
<br />
char temp[10]; <br />
<br />
sizeof(temp) -> is size of pointer in C – currently that is 4 bytes<br />
sizeof(temp) -> is size of object in C++ - which is 10 characters<br />
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
|
I'm glad you got your answer, but please don't post C questions in the C++/CLI forum in future.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
tell me about void in c language
|
|
|
|
|
you should be more specific.
Generally, void is used in functions.
1)If the function does not return any value,ex:
<br />
void Print_Numbers (int i)<br />
{<br />
for (i;i<100;i++)<br />
cout<<i;<br />
}<br />
When you call the above function, you should send an integer parameter,say n, and the function will print the values from n to 1000. No return type is needed, that is, void will be set as a return value.
2)You can have the parameter also to be void instead of (i). In this case you should initialize the variable i inside the function.
I hope this is what are you looking for,
|
|
|
|
|
thanks for ur response....
but i need significance of "void"
|
|
|
|
|
|
Void: The total absents of anything.
1) If void it the return type, then the function returns nothing.
2) If void is an argument to a function, then the function takes no arguments.
3) If you convert a pointer to a variable to a pointer to void, it means that only you (normally) know what type it origanaly was. Very handy for passing around indirect references (pointers) to types, but dangrous if the reciever converts it to a variable type other than the original type. By the way most modern operating systems depend on this ability, because message passing requires the ability to pass references (actually indirect references) around.
It is that simple.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
could anyone help me with the projrct on streamline allocation i.e i need a complete coding for this project.actually in this C++ program i have to allocate marks to students on the basis of their performance in exams
|
|
|
|
|
Are you using C++ or C++/CLI?
and please be more specific in your question.
show us what have you done so far and what problems did you encounter to be able to help you.
|
|
|
|