什么是c ++中的编译错误?

时间:2016-11-19 09:30:28

标签: c++ compiler-errors

我正在参加在线比赛。我的代码在我的compilier visual studio 2013中工作。但在线评委给我编译错误。 这是我的代码。

    #include<iostream>
#include<string>
#include<cmath>
#include<fstream>
using namespace std;

void main() {

    int first_number;
    int  second_number;

    string str;
    char ch;
    int count = 0;

    ifstream yfile("q4.txt");

    while (!yfile.eof())
    { 
        yfile >>first_number;

        if (first_number < 0)
            first_number = abs(first_number);

        yfile >> ch;
        yfile >> second_number;

        if (second_number < 0)
            second_number = abs(second_number);

        int  gcd;
        for (int i = 1; i <= first_number&&i <= second_number; i++){


            if (first_number%i == 0 && second_number%i == 0){

                gcd = i;

            }

        }

        cout << "Output:    " << gcd << endl;



    }

任何人都可以告诉我解决方案吗?我会感激你的。 }

1 个答案:

答案 0 :(得分:1)

  1. 发布的代码最后有一个缺少大括号。

  2. error: ‘::main’ must return ‘int’
    尝试使用
    int main() {
    代替。并在末尾添加return 0;语句(或任何你想要的返回值)。