473,699 Members | 2,311 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2486
* 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
3973
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 variable **var make it an array of pointers? I realize that 'char **var' is a pointer to a pointer of type char (I hope). And I realize that with var, var is actually a memory address (or at
33
3172
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
3646
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 serializing the object array). I can think of three ways to do this:
10
4967
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 declared char** format = NULL; Now the problem starts. Each time strtok() returns me a token (which is char*), I call malloc() and I (want to) store the address returned in the array format, and copy the token to that address. code snippet:
3
9524
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++ code (ie. wrappers etc). In Managed C++ there was an automatic conversion between const char* and String^. This was useful to us for two reasons: 1. We declared our string constants as eg. const char* const c_My_Constant = "blah", and these...
20
3552
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
13637
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, hash<const char*>, eqstrmonths; months = 31; I think it is for the use in calls like function("my string"), but, is it really necessary to define funcion(const char*) besides
13
7956
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 myDoubleQuote = (char)34; string myDoubleQuote = "" + (char)34;
7
6990
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 wall. I'm trying to convert the following two structures from their c++ versions to their vb.net versions. I cannot be sure which is the problem because both must be passed at the same time. The error I am getting is thrown by the object and...
0
8613
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9172
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8908
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8880
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7745
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4374
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2344
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.