pack char in a line

I have a question


how would you packs 4 characters at a time from the line into an integers ?

Last edited on
you mean to read line 123456789012 as integers 1234, 5678 and 9012?
In that case:

1
2
3
4
5
6
int getint(std::istream& in)
{
    char buff[5] = { 0 };
    in.read(buff, 4);
    return std::atoi(buff);
}
I mean character, for example:

the word " Format " has 6 char

I want to take 4 char only, to get their values, then the the 2 char left take their values alone
Ok, drop the atoi and you got a 4 char array.
so it would be just like this

1
2
3
4
5
6
int getint(std::istream& in)
{
    char buff[5] = { 0 };
    in.read(buff, 4);
    return (buff);
}



??
You (a) cannot return an array like that and (b) have wrong return type.
You do not even need the function anymore.

Just do char buff[4]; //or char buff[5] = { 0 }; if you want to threat it as c-string and then do std::cin.read(buff, 4); //or use whichever stream you need every time you need another portion of characters.
Topic archived. No new replies allowed.