注册 登录
编程论坛 C++教室

有没有大神帮忙看看, 为什么我这个程序报错耶????

后卿 发布于 2022-05-15 17:01, 921 次点击
#include "string"
#include<ctime>
using namespace std;
int main()
{
    int arr[10]={300,350,200,400,250,500,434,456,425,452};
    int tmp;

    int end=sizeof(arr)/sizeof(arr[0])-1;
    for (int start=1;start<end;start++)
    {
        if (arr[start-1]>arr[start])
            {
                tmp=arr[start];
                arr[start]=arr[start-1];
                arr[start-1]=tmp;
            }
    }
    for(int i=0;i<=end;i++)
    {
        cout<<arr[i]<<endl;
    }
    system("pause");
    return 0;
2 回复
#2
后卿2022-05-15 17:14
好了,就多了一行空格,我也不知道为什么一行空格会运行不了
#3
yahooboby2022-05-24 13:27
第一行#include "string"改成#include <string>
再加上一行 #include <iostream>
最后一行少加一个 }
vs2019直接运行成功。。
1