473,322 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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

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


Nov 29 '06 #1
2 2467
* 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?
Nov 29 '06 #2
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

Nov 29 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: jab3 | last post by:
(again :)) Hello everyone. I'll ask this even at risk of being accused of not researching adequately. My question (before longer reasoning) is: How does declaring (or defining, whatever) a...
33
by: baumann.Pan | last post by:
hi all, i want to get the address of buf, which defined as char buf = "abcde"; so can call strsep(address of buf, pointer to token);
33
by: Mark P | last post by:
A colleague asked me something along the lines of the following today. For some type X he has: X* px = new X; Then he wants to convert px to a char* (I'm guessing for the purpose of...
10
by: yogeshmk | last post by:
I need to break a longer string (with strtok()) and store the smaller strings in an array. since the number of small strings is not fixed/known, I cannot use a declaration like char *format, so I...
3
by: Kevin Frey | last post by:
I am porting Managed C++ code from VS2003 to VS2005. Therefore adopting the new C++/CLI syntax rather than /clr:oldSyntax. Much of our managed code is concerned with interfacing to native C++...
20
by: liujiaping | last post by:
I'm confused about the program below: int main(int argc, char* argv) { char str1 = "abc"; char str2 = "abc"; const char str3 = "abc"; const char str4 = "abc"; const char* str5 = "abc";
14
by: Javier | last post by:
Hello, in which cases is it better the use of "const char*" to "string" (or even const string &). I mean, in STL (http://www.sgi.com/tech/stl/hash_map.html) I see: hash_map<const char*, int,...
13
by: xzzy | last post by:
None of the following properly do the VB.net double quote conversion because all of the following in csharp convert to \" instead of just a double quote: " I have tried: char...
7
by: edsunder | last post by:
I'm making a "wrapper" for an unmanaged DLL (written, I'm fairly certain in C). I have a c++ "wrapper" that I'm trying to convert to VB.net. I've got most of the program working, but I've hit a brick...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.