C++ 连接无符号字符[]值并转换为字符*

C++ 连接无符号字符[]值并转换为字符*,c++,android-ndk,java-native-interface,C++,Android Ndk,Java Native Interface,我使用JavaNDK是为了使用C结构从“bin”文件中提取一些信息。我必须在for循环中提取有关网关的信息。我可以提取信息,但我需要连接结果并添加点,以便打印最终IP并将其转换为char*或string。 我使用了reinterpret\u cast,但它不起作用 如何将IP地址转换为字符串 #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__) //Gateway.info[4] is

我使用JavaNDK是为了使用C结构从“bin”文件中提取一些信息。我必须在for循环中提取有关网关的信息。我可以提取信息,但我需要连接结果并添加点
,以便打印最终IP并将其转换为
char*
string
。 我使用了
reinterpret\u cast
,但它不起作用

如何将IP地址转换为字符串

#define  LOGD(...)  __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)

//Gateway.info[4] is unsigned char type
int config_len = sizeof(ptr->Gateway.info);
for (int i = 0; i < config_len; i++) {
    int number = ptr->Gateway.info[i];

}
LOGD("GATEWAY %d",number);
#定义LOGD(…)uu android_uLog_u打印(android_uLog_u调试、日志标签、参数)
//Gateway.info[4]是无符号字符类型
int config_len=sizeof(ptr->Gateway.info);
对于(int i=0;iGateway.info[i];
}
LOGD(“网关%d”,编号);

我犯了一个错误。它起作用了

#define  LOGD(...)  __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)


string Result; 
ostringstream convert;

//Gateway.info[4] is unsigned char type
int config_len = sizeof(ptr->Gateway.info);
for (int i = 0; i < config_len; i++) {
    int number = ptr->Gateway.info[i];
    convert << number; 
    Result = convert.str()

}
#定义LOGD(…)uu android_uLog_u打印(android_uLog_u调试、日志标签、参数)
字符串结果;
ostringstream转换;
//Gateway.info[4]是无符号字符类型
int config_len=sizeof(ptr->Gateway.info);
对于(int i=0;iGateway.info[i];

convert是
LOGD
使用?那么将
char
打印为小整数的格式是
%hhd”
。或
%hhu<代码>未签名char <代码>。是的,它使用了打印格式。问题是使用代码> RealTytPask< /Cord>。因为C语言没有这个特性。也许你应该正确地更新你的语言标签。C++中的C语言或C++语言可以使用<代码> STD::OSTRIGSTROME <代码>,这不是C语言。@ ToMatasMattws
c++
。我使用了这两种方法,但当我打印字符串时,字符串是空的。-方法1
std::string sName(重新解释转换(ptr->Gateway.info))
-方法2
int number;string Result;ostringstream convert;convert看起来这是最好的答案。如果你这么认为,那就接受它。但是,我认为你应该把
Result=
移到循环下面。它只需要调用一次。