How to convert *char into int??

here is a source that i am working on.

class A
{
public :
char * m_pbuff;

KcFile(){m_pbuff = (char *)malloc(128);}
......
};

int main()
{
A tmp;
int *p_int, *p_float;
int a = 10; float b= 10.5;
p_int = &a; p_float = &b;
memcpy(tmp.m_pbuff, p_int, sizeof(int));
tmp.m_pbuff = m_pbuff + 4;
memcpy(tmp.m_pbuff, p_float, sizeof(float));
tmp.m_pbuff = m_pbuff + 4;

-> And then i wanna read all data in tmp.m_pbuff.
however, I think i have to convert it into proper data type.
I don't know how to do.
I need any help. thank you in advance.
}
You could use a stringstream to convert it.
1
2
3
4
5
6
std::stringstream ss;
ss<<"3142";
int a;
if(ss>>a && ss.empty()) {
   // things are good
}
What you are doing now is copying bytes from one place to another. The data types involved don't affect anything. I don't see what you are trying to achieve. While your title implies that you want to convert a string to an integer, you don't have a string. Is it the other way? In either case, Zhuge gave the right answer.
that small snippet that Zhuge posted wont compile. it says it doesnt know what ss.empty is. there is no function empty in stringstream.
It's true. stringstream has no member empty():
http://cplusplus.com/reference/iostream/stringstream/
Topic archived. No new replies allowed.