cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
Quesion with char
Quesion with char
Jun 9, 2012 at 4:37pm UTC
MAQAH
(20)
Hey guys ny one knows how to take the characters of a character array as groups.
eg: char ch[]="987652345v" // assume this is an id no
So what I want is take the first two numbers (98) to one char variable or int or any kind of variable so I can use it for calculations or .......
Any suggestion ?
Thank You ..!!!!!!!
Jun 9, 2012 at 4:42pm UTC
Athar
(4466)
You should not use char arrays/C strings.
1
2
3
string str=
"987652345v"
; string firstTwo=str.substr(0,2); cout << firstTwo;
See here:
http://www.cplusplus.com/reference/string/string/
Last edited on
Jun 9, 2012 at 4:47pm UTC
Jun 9, 2012 at 4:46pm UTC
MAQAH
(20)
ok Thanks a lot ,.. for that
could you please tell me the real difference between char and string ?
Jun 9, 2012 at 4:48pm UTC
Athar
(4466)
std::string is a C++ type for handling strings. It manages memory automatically and provides various useful functions, as you can see in the reference.
There's generally no good reason to use char arrays in C++.
Jun 9, 2012 at 4:50pm UTC
MAQAH
(20)
hm Great .
Thanks ..!!
Topic archived. No new replies allowed.