需要有关“如何使用strstream"的帮助! [英] need help about "how to use strstream"!
本文介绍了需要有关“如何使用strstream"的帮助!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要在缓冲区[3]中使用"172",但现在是"1".我要使用."在点.你能告诉我怎么做吗?
#include >< stdio.h >
#include < tchar.h >
#include < strstream >
使用 命名空间 std;
int _tmain( int argc,_TCHAR * argv [])
{
字符点;
字符缓冲区[ 4 ];
strstream strs;
strs<< " ;
strs>> buffer [ 3 ]>>点>> buffer [ 2 ]>>> > buffer [ 1 ]>>点>> buffer [ 0 ];
printf(" ,*((( int *)buffer));
返回 0 ;
}
我只想使用strstream.
解决方案
由于缓冲是一个字符数组,因此您正在回送一个字符.将其声明为整数类型的数组.
例如
int buffer[4];
为什么不尝试像strtok()这样的字符串标记程序?
http://www.cplusplus.com/reference/clibrary/cstring/strtok/
I want "172" in buffer[3] but now it is "1".and i want "." in dot. can you tell me how to do?
#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.
解决方案
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];
Why don''t you try a string tokenizer like strtok()?
http://www.cplusplus.com/reference/clibrary/cstring/strtok/
这篇关于需要有关“如何使用strstream"的帮助!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文