Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > char int string ,the different? and string 2 double convent problem.

Reply
Thread Tools

char int string ,the different? and string 2 double convent problem.

 
 
key9
Guest
Posts: n/a
 
      11-29-2006
Hi all

on reading code I found these function

int foo(int char);
char foo(char ch_);

string foo(string ch);


I know the different between char and the string

char[]: 'this is char\0'
string: 'this is string'
What about int?


Also
How to corvent string to double, for example

string: 12.0317 to double

an "safe" conversion should first confirm the '12.0317' is double
using regexp? that's too big.
or buy scan the string using isdigital()?

and what about 002.0317?


thank you
key9




 
Reply With Quote
 
 
 
 
mlimber
Guest
Posts: n/a
 
      11-29-2006
key9 wrote:
> on reading code I found these function
>
> int foo(int char);
> char foo(char ch_);
> string foo(string ch);


Assuming you mean std::string, that should *probably* be:

string foo( const string& ch);

>
>
> I know the different between char and the string
>
> char[]: 'this is char\0'


No, that's a character array. A char like the parameter to foo() is a
single character.

> string: 'this is string'
> What about int?


An int is a number, a primitive data type in C++. What more do you want
to know?

Your real question is probably related to function overloading.

foo( 1 ); // Calls foo(int)
foo( '1' ); // Calls foo(char)
foo( "1" ); // Calls foo(string)

> Also
> How to corvent string to double, for example
>
> string: 12.0317 to double
>
> an "safe" conversion should first confirm the '12.0317' is double
> using regexp? that's too big.
> or buy scan the string using isdigital()?
>
> and what about 002.0317?


http://www.parashift.com/c++-faq-lit....html#faq-39.2

Cheers! --M

 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      11-29-2006
* key9:
> Hi all


Hi hi!


> on reading code I found these function
>
> int foo(int char);
> char foo(char ch_);
>
> string foo(string ch);
>
>
> I know the different between char and the string
>
> char[]: 'this is char\0'
> string: 'this is string'


Well, almost. If the idea is that a char /array/ is zero-terminated,
then you have it almost right. It's not necessarily zero-terminated (in
fact there are zillions of string formats), but the most common format,
and the one you get for a literal string constant such as "uhuh", is
zero-terminated.

Example (off the cuff):

#include <cstdio> // strlen
#include <iostream> // cout
#include <ostream> // <<, endl
#include <string> // string

int main()
{
using namespace std;

char const s[] = "uhuh";
string const t = s; // Copy, in std::string format.

cout << sizeof( s ) << endl; // 5, not 4.
cout << strlen( s ) << endl // 4.
cout << t.length() << endl; // 4.
}


> What about int?


It's an integer type. You can do integer arithmetic.



> Also
> How to corvent string to double, for example
>
> string: 12.0317 to double


boost::lexical_cast

Install the Boost library.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Photos and report of a Cycling Ride to the Teotihuacan Archaeological Site + Acolman Augustine Ex-Convent (Mexico State. MX) erasmo Digital Photography 1 08-22-2007 01:55 AM
(const char *cp) and (char *p) are consistent type, (const char **cpp) and (char **pp) are not consistent lovecreatesbeauty C Programming 1 05-09-2006 08:01 AM
int main(int argc, char *argv[] ) vs int main(int argc, char **argv ) Hal Styli C Programming 14 01-20-2004 10:00 PM
newbie: char* int and char *int trey C Programming 7 09-10-2003 03:24 AM
dirty stuff: f(int,int) cast to f(struct{int,int}) Schnoffos C Programming 2 06-27-2003 03:13 AM



Advertisments