我现在正在学校学习C++.目前在我的windows vista笔记本电脑上使用带有代码块的C++.我注意到每当我尝试使用Clibrary导入的类中的函数时,我在控制台中都会出错.
"'hi'未被记录为内部或外部命令,可操作命令或批处理文件"
我的代码看起来像这样......
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
system("hi");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
只是简单的你可以看到,但我得到了这个错误.我可以使用iostream很好,我已经测试了io include并且有效......我需要安装其他东西以便能够使用cstdlib吗?
谢谢你,扎克史密斯
这是我一直在关注的教程,我已经完成了它所说的一切,但它不起作用。我有三个文件:main.cpp、burrito.h(类)和 burrito.cpp。
这里分别是三个文件。
主程序
#include <iostream>
#include "Burrito.h"
using namespace std;
int main() {
Burrito bo;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
墨西哥卷饼
#ifndef BURRITO_H
#define BURRITO_H
class Burrito {
public:
Burrito();
};
#endif // BURRITO_H
Run Code Online (Sandbox Code Playgroud)
墨西哥卷饼
#include <iostream>
#include "Burrito.h"
using namespace std;
Burrito::Burrito() {
cout << "Hello World" << endl;
}
Run Code Online (Sandbox Code Playgroud)
当我构建并运行时,出现以下错误:
...undefined reference to `Burrito::Burrito()'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 6 seconds)
1 errors, 0 warnings
Run Code Online (Sandbox Code Playgroud)
我正在使用 CodeBlocks 进行编译。
我已经为这个问题尝试了很多不同的解决方案,我似乎无法弄清楚为什么编译器继续在我的头文件中给我这个错误.如果有人能给我一些见解,那将非常感激.编辑:抱歉忘了哪一行给出错误.它在头文件中的行:Date(string mstr,int dd,int yy);
是的,我知道这个=新的日期...是一个糟糕的解决方案,我只是稍微研究一下;)
标题:
#include <string>
#ifndef DATE_H
#define DATE_H
class Date{
public:
Date(int mm, int dd, int yy);
Date(string mstr, int dd, int yy);
void print();
void printFullDate();
void prompt();
void setMonth(int);
void setDay(int);
void setYear(int);
int getMonth();
int getDay();
int getYear();
static const int monthsPerYear = 12;
private:
int month;
int day;
int year;
int checkDay(int);
};
#endif
Run Code Online (Sandbox Code Playgroud)
如果你需要它,这是实现(它还没有完全完成,我只是试图测试我写的一些函数):
#include <iostream>
#include <stdexcept>
#include "Date.h"
using namespace std;
Date::Date(int mm, int dd, int yy){
setMonth(mm);
setYear(yy); …Run Code Online (Sandbox Code Playgroud) 我一直在尝试编译最基本的SDL应用程序,但无论我做什么,我都会遇到这个错误:
c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.4.1/../../../libmingw32.a(main.o):main.c:(.text+0xd2): undefined reference to `WinMain@16'
Run Code Online (Sandbox Code Playgroud)
我为此搜索了解决方案,但它们都与Visual C++或缺少的主要内容有关.我没有使用Visual C++,我已经定义了main.
这是我的代码:
#include "SDL/SDL.h"
int main( int argc, char* args[] )
{
//Start SDL
SDL_Init( SDL_INIT_EVERYTHING );
//Quit SDL
SDL_Quit();
return 0;
}
Run Code Online (Sandbox Code Playgroud) 当我在Code ::中创建新项目时,int main ( int argc, char *argv[] )缺少main.c 中的块.相反,main.c的签名就像这样构建:int main().我怎么能改变这个?
我看到一些代码有括号,没有""if或"for"或"do"或任何东西,只有评论.
像这样
//一些评论
{
int a = 5;
//和更多代码
}
这是什么?
注意:我注意到在使用我的IDE(代码:: blocks)时,左边有" - ",当你单击它时,它会隐藏括号中的所有代码.这是括号中唯一没有声明的用法吗?
这个我的程序从c ++中的函数返回数组
#include <iostream>
using namespace std;
int *pTest(){
static int a[] = {2,3,4,6,9};
return a;
}
int main(){
int *x;
x = pTest();
while(*x != NULL){
cout << *x++ << " ";
}
}
Run Code Online (Sandbox Code Playgroud)
根据我的输出应该是2 3 4 6 9
我的机器输出2 3 4 6 9 1,
为什么1在输出中有额外的.
我正在使用codeblocks,gcc 4.8.1
#include <iostream>
using namespace std;
int main(){
int intake;
cout<<"Enter the maximum number of intake in this session of 2015, September: ";
cin>>intake;
for(int i=20150900; i<intake+20150900; i++){
cout<<"Enter the total percentage of Student ID numbered #"<<i<<": ";
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这是我的代码,当我在code :: blocks上编译它时会出现以下错误.我是linux OS的新手,所以我不太了解它是如何工作的.谢谢你的帮助!:) 错误信息:
g ++ -c /home/subbs/Desktop/entrance_exam/main.cpp -o /home/subbs/Desktop/entrance_exam/main.o/bin/sh:1:g ++:not found
我正在使用代码块在C++中做作业.任务是编写一个程序,确定一个数字是奇数还是偶数.代码如下.
#include <iostream>
using namespace std;
int number;
int main()
{
cout<<"Please enter number"<<endl;
cin>>number;
if(number%2==0)
{
cout<<"The number:"<<number<<" is even" <<endl;
}
else()
{
cout<<"The number:"<<number<<" is odd" <<endl;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud) 当我使用终端命令编译并运行以下代码时(在linux mint sonya中)
gcc -o program program.c
./program
我遇到了分段错误.当我使用Code :: blocks IDE执行相同操作时,我不会收到任何错误.我知道访问非法内存时会出现分段错误.怎么了?
#include <stdio.h>
int main()
{
int t;
scanf("%d",&t);
for(t;t>0;t--)
{
int i,j,n,arr[n],sump=0,sums=0,total,ans;
scanf("%d",&n);
for(i=0;i<=n-1;i++) scanf("%d",&arr[i]);
for(i=0;i<=n-1;i++,sump=0,sums=0)
{
for(j=0;j<=i;j++) sump=sump+arr[j];
for(j=n-1;j>=i;j--) sums=sums+arr[j];
if(i==0) ans=sump+sums;
else if(ans>sump+sums) ans=sump+sums;
}
for(i=0;i<n;i++,sump=0,sums=0)
{
for(j=0;j<=i;j++) sump=sump+arr[j];
for(j=n-1;j>=i;j--) sums=sums+arr[j];
if(ans==sums+sump) break;
}
printf("%d\n",i+1);
}
}
Run Code Online (Sandbox Code Playgroud)