小编Sim*_*kov的帖子

在头文件中使用const

在file.h中:

 extern const int ONE;
Run Code Online (Sandbox Code Playgroud)

在file.cpp中

#include "file.h"
const int ONE = 1;
Run Code Online (Sandbox Code Playgroud)

在main.cpp中

#include <iostream>
#include "file.h"
int main()
{
    std::cout << ONE << std::endl;
}
Run Code Online (Sandbox Code Playgroud)

问题:为什么我必须#include "file.h"在file.cpp中使用?有一个定义ONE.

谢谢

c++ const header

4
推荐指数
1
解决办法
138
查看次数

向量中的例外C++

#include <vector>
#include <iostream>
#include <map>
#include <string>
using namespace std;
vector<char> prime;
char a='t';
int number;
int sqrt_of_n;
int main(){
  try{
      cin >> number;
      sqrt_of_n = round(sqrt(number));
      for (int i = 0; i < number; i++) prime.push_back(a);//?????????? ???????
      for (int i = 2; i < sqrt_of_n; i++)
      {
          for (int j = 3; j < number; j++)
          {
              if ((j%i == 0) && (j!=i)) prime[j] = 'f';
          }
      }
      for (int i = 0; i <= prime.size(); i++)
      if …
Run Code Online (Sandbox Code Playgroud)

c++ exception

-4
推荐指数
1
解决办法
127
查看次数

标签 统计

c++ ×2

const ×1

exception ×1

header ×1