iawyso 发表于 2013-6-21 12:42:37

C++的一点问题

// 222.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "stdio.h"
#define CL 10
int main(int argc, char* argv[])
{
int a;
float b;
double c;
char d;
a=10;
b=10.55;
c=1.25e15;
d="A"
printf("a=%d a=%f c=e% d=%c",a,b,c,d)

return 0;
}


这里哪里错了??老出现错误

--------------------Configuration: 222 - Win32 Debug--------------------
Compiling...
StdAfx.cpp
Compiling...
222.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\222\222.cpp(16) : warning C4305: '=' : truncation from 'const double' to 'float'
C:\Program Files\Microsoft Visual Studio\MyProjects\222\222.cpp(19) : error C2440: '=' : cannot convert from 'char ' to 'char'
      This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\Program Files\Microsoft Visual Studio\MyProjects\222\222.cpp(19) : error C2146: syntax error : missing ';' before identifier 'printf'
C:\Program Files\Microsoft Visual Studio\MyProjects\222\222.cpp(22) : error C2143: syntax error : missing ';' before 'return'
执行 cl.exe 时出错.
222.exe - 1 error(s), 0 warning(s)

帮忙看下


jacky7788 发表于 2013-6-21 13:46:01

头文件打错,还有少了结束的;
改成

// 222.cpp : Defines the entry point for the console application.
//

#include "stdio.h"
#define CL 10
int main(int argc, char* argv[])
{
int a;
float b;
double c;
char d;
a=10;
b=10.55;
c=1.25e15;
d="A";
printf("a=%d a=%f c=e% d=%c",a,b,c,d);

return 0;
}

jacky7788 发表于 2013-6-21 13:47:14

补充下,那个不是打错

hackfz 发表于 2013-6-21 14:27:09

d="A";这里有错。

恋恋恋,你 发表于 2013-6-21 18:41:24

d="A"不能直接吧字符串赋给数组
printf这句缺个逗号,

Output 发表于 2013-6-21 22:47:24

本帖最后由 Output 于 2013-6-21 22:53 编辑

#include "stdafx.h"

#include <stdio.h>
#define CL 10
int main(int argc, char* argv[])
{
int a;
float b;
double c;
char d;
a=10;
b=10.55f;
c=1.25e15;
d='A';
printf("a=%d b=%f c=%e d=%c",a,b,c,d);

return 0;

}你可知道你连代码都写错了
页: [1]
查看完整版本: C++的一点问题