C/C++文字列処理

417 ワード

1、sprintfによる文字列接合
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char **argv)
{
    char *str = (char *)malloc(sizeof(char) * 1);

    int i = 1234;
    char *tmp = "other string";

    sprintf(str, "some string %d some string %s", i, tmp);

    printf("str = %s
", str); free(str); return 0; }

2、etc