【问题标题】:what is compilation error in c++? [closed]c++中的编译错误是什么? [关闭]
【发布时间】:2017-04-03 03:25:51
【问题描述】:

我正在参加在线比赛。我的代码在我的编译器 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;



    }

谁能告诉我解决方案?我会感谢你的。 }

【问题讨论】:

  • 在线评委遇到什么编译错误?
  • 他们只是响应“无编译错误”
  • void main() { 这是未定义的行为。请使用程序的有效入口点之一。例如int main() {.
  • 你的{}
  • 好的..我正在检查

标签: c++ compiler-errors


【解决方案1】:
  1. 发布的代码末尾缺少一个花括号。

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

【讨论】:

  • 这里的花括号是我在发布代码时的错误。我现在正在尝试 int main(){}。希望它可以工作
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-13
  • 1970-01-01
  • 1970-01-01
  • 2010-09-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多