int a=10;
char* buf=malloc(100);
sprintf(buf,"vashe chislo=%d",a);
printf(buf);
free(buf);
return 0;
#include <stdlib.h>
#include <stdio.h>
void func(const char * str)
{
}
int main(int argc, char* argv[])
{
int a=10;
char* buf=new char[100];
sprintf(buf,"vashe chislo=%d",a);
printf(buf);
delete[] buf;
return 0;
}
/*
* File: main.cpp
* Author: Micren
*
* Created on 29 Октябрь 2010 г., 19:08
*/
#include <iostream>
#include <sstream>
#include <cstring>
#include <cstdio>
/*
*
*/
const size_t STR_SIZE = 100;
void func(const char* const str)
{
std::cout << str << std::endl;
}
void func(const std::string& str)
{
std::cout << str << std::endl;
}
int main(int argc, char** argv)
{
int a = 10;
// 1й вариант
std::stringstream sstream;
sstream << "Ваше число: " << a;
func(sstream.str());
// 2й вариант
try
{
char* str = new char[STR_SIZE];
strcpy(str, "Ваше число: ");
sprintf(str, "%s%i", str, a);
func(str);
delete[] str;
}
catch (std::bad_alloc)
{
std::cerr << "Не могу выделить память" << std::endl;
return 1;
}
return 0;
}
Ваше число: 10
Ваше число: 10
#pragma warning(disable:4996)
int a=20;
char buf[64];
bytes=sprintf_s(buf, "Здесь число %i", a);
Если Вы уже зарегистрированы на Портале - войдите в систему, если Вы еще не регистрировались - пройдите простую процедуру регистрации.