小七技术论坛,计算机安全和杀毒软件,编程交流于软件安全技术交流,给新手一个绿色安全的论坛

标题: C++的一点问题 [打印本页]

作者: iawyso    时间: 2013-6-21 12:42
标题: 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 [2]' 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
头文件打错,还有少了结束的;
改成

// 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
补充下,那个不是打错
作者: hackfz    时间: 2013-6-21 14:27
d="A";  这里有错。
作者: 恋恋恋,你    时间: 2013-6-21 18:41
d="A"不能直接吧字符串赋给数组
printf这句缺个逗号,
作者: Output    时间: 2013-6-21 22:47
本帖最后由 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;

}你可知道你连代码都写错了





欢迎光临 小七技术论坛,计算机安全和杀毒软件,编程交流于软件安全技术交流,给新手一个绿色安全的论坛 (https://xqmsyk.com/) Powered by Discuz! X3.3