早教吧 育儿知识 作业答案 考试题库 百科 知识分享

一个简单的C++格式转换问题,#include"stdio.h"#include"iostream.h"voidmain(){doublex=33.3;doubley=22.2;char*str[2];sprintf(str[0],"%.3f",x);sprintf(str[1],"%.3f",y);cout

题目详情
一个简单的C++格式转换问题,
#include "stdio.h"
#include "iostream.h"
void main()
{
double x=33.3;
double y=22.2;
char *str[2];
sprintf(str[0],"%.3f",x);
sprintf(str[1],"%.3f",y);
cout
▼优质解答
答案和解析
#include "stdio.h"
#include "iostream.h"
void main()
{
double x=33.3;
double y=22.2;
char *str[2];
str[0] = new char[5];
str[1] = new char[5];
sprintf(str[0],"%.3f",x);
sprintf(str[1],"%.3f",y);
cout