C++ 入门 怎么这都错 ?

来源:百度知道 编辑:UC知道 时间:2024/06/06 04:44:13
C++ 写

main()
{
printf("This is a program /n")
}

--------------------Configuration: 11 - Win32 Debug--------------------
Compiling...
1.cpp
d:\microsoft visual studio\myprojects\11\1.cpp(3) : error C2065: 'printf' : undeclared identifier
d:\microsoft visual studio\myprojects\11\1.cpp(4) : error C2143: syntax error : missing ';' before '}'
d:\microsoft visual studio\myprojects\11\1.cpp(4) : warning C4508: 'main' : function should return a value; 'void' return type assumed
执行 cl.exe 时出错.

1.obj - 1 error(s), 0 warning(s)

#include<stdio.h>
int main()
{
printf("This is a program\n");
}
帮你改成这样,还有,后面那里是\n,不是/n,如果是/n,那么输出就是:
This is a program /n
这样了。

你这个写的不是C++
应该这样
#include<iostream>
using namespace std;
int main()
{
cout<<"This is a program /n";
return 0;
}

你这是c程序 不是C++
C++ 应该这么写
#include <iostream>
using namespace std;
void main()
{
cout<<"This is a program "<<endl;
}

我写个程序供你参考里面既有c++代码又有c代码是可以编译运行的!
仔细看了一下你建的的project是win32的!而我们所写的是console application的
#include <string>
#include <iostream>
using namespace std;
int main()
{
char d[20]="Golden Global ";
char *s=" View";
string str="Come on";
char c='9';
strcat(d,s);
cout<<str<&l