LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-17-2005, 12:28 AM   #1
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203

Rep: Reputation: 45
type cast


Hi... whats the easiest way for converting an integer, double e.tc to a string?
Do u have some good articles for type casting?

I have written a simple function for writing things to a file... the problem is that the function take only two arguments a string to write in the file and the file path of the file... After using my function i have noticed that isnt so easy to store integers and results from other functions so i need your help to modify my function...
Any good suggestions?
Thxx a lot
 
Old 07-17-2005, 12:32 AM   #2
dr_zayus69
Member
 
Registered: Sep 2004
Location: western massachusetts
Distribution: fedora core 3, Suse 10
Posts: 877

Rep: Reputation: 35
what language are you writing in?
 
Old 07-17-2005, 04:58 AM   #3
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Type casting and converting numbers to strings are unrelated. Check out this site for what you are looking for:
http://www.cplusplus.com/ref/cstdlib/index.html

These work for C and C++, but in C++ you need to #include cstdlib instead of stdlib.h. Also, some C++ compilers put some/all/none of these functions in namespace std, so watch out for that.

As far as casting, in C all you need to do is put the type to be casted to in parens:
int Num = (int) 'a';

That is frowned upon in C++, however. Take a look here for casting in C++:
http://www.cplusplus.com/doc/tutorial/tut5-4.html

The C-cast is equivalent to reinterpret_cast when used in C++, and can be dangerous when dealing with classes. It does serve useful for turning objects into raw data however (unsigned char).
ta0kira
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
can you cast arrays? (c++) nadroj Programming 7 10-13-2005 01:34 AM
type cast from int to QString spoody_goon Programming 2 05-24-2005 06:14 AM
pointer from integer without a cast bcf2 Programming 7 12-30-2004 02:04 PM
what does a cast in c++ actually do? markhod Programming 2 12-23-2004 09:01 AM
Question on type cast cxel91a Programming 2 12-05-2003 09:13 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration