首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >C++编译后的头收到大量错误

C++编译后的头收到大量错误
EN

Stack Overflow用户
提问于 2019-03-26 07:27:38
回答 1查看 75关注 0票数 -4

我收到错误,如cout是未声明的标识符

我已经经历了很多次了,我看不出我做错了什么!我知道,所以请耐心等待。

我已经检查过很多次了,这对我来说是不可能的。

Main.cpp

代码语言:javascript
复制
#include <iostream>
#include <limits>
#include "add.h"


int main()
{
    std::cout << "this will call function which will have you type in numbers which when done will call the second function as well as giving the second function answers to what it needs. " << '\n';

    int numOne{ function() };
    int numTwo{ function() };
    std::cout << "With those two numbers we can add them! and our answer is!" << functionTwo(numOne, numTwo) << '\n';
    std::cout << "we now sent functionTwo the numbers we made using function for simplness. Now functionTwo can have the numbers it needs to do what it needs to do." << '\n';


    // This code will make it not close automatically.
    std::cin.clear();
    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
    std::cin.get();

    return 0;
}

add.cpp

代码语言:javascript
复制
#include <iostream>
#include "add.h"

int functionTwo(int a, int b)

{
    std::cout << " fdsaf dasf dsa" << '\n';


    std::cout << 2 * a << '\n';
    std::cout << 2 + b << '\n';
    int c{ 2 + b };
    int d{ 2 * a };



    return c + d;

}

add2.cpp

代码语言:javascript
复制
#include <iostream>
#include "add.h"
int function()

{
    int a{ 0 };
    std::cin >> a;
    return a;

}

add.h

代码语言:javascript
复制
#ifndef _IOSTREAM_
#define _IOSTREAM_

int function();



int functionTwo(int a, int b);



#endif

我正在使用Microsoft Visual studio,并且正在尝试编译这段代码。我确保创建了新项目/ .cpp文件和.h文件。我尝试删除了pch.h和pch.cpp文件,但我就是不明白我做错了什么。请帮帮我。我知道,所以我对此感到抱歉。

EN

回答 1

Stack Overflow用户

发布于 2019-03-26 08:48:46

您要做的是添加:

代码语言:javascript
复制
#include "pch.h"
#include "add.h"

因此,在每个使用头文件add.h的文件中,请确保在它上面也使用了pch.h,否则它会告诉您您忘记使用它了,它将无法工作。只需添加#include "pch.h"就可以解决所有问题。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55347824

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档