Click here to Skip to main content
15,882,114 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want "172" in buffer[3] but now it is "1".and i want "." in dot. can you tell me how to do?

C++
#include <stdio.h>
#include <tchar.h>
#include <strstream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
    char dot;
    char buffer[4];
    strstream strs;
    strs << "172.24.41.40";
    strs >> buffer[3]>>dot>>buffer[2]>>dot>>buffer[1]>>dot>>buffer[0];
    printf("%d",*((int*)buffer));
    return 0;
}



i just want to use strstream.
Posted
Updated 29-Jun-10 19:50pm
v3

You are streaming back a character since buffer is a character array. Declare it as an array of integer type.
E.g.
int buffer[4];
 
Share this answer
 
Comments
Nish Nishant 13-Jul-10 11:10am    
Reason for my vote of 5
Worth 5!
Why don't you try a string tokenizer like strtok()?
http://www.cplusplus.com/reference/clibrary/cstring/strtok/
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900