我收到错误,如cout是未声明的标识符
我已经经历了很多次了,我看不出我做错了什么!我知道,所以请耐心等待。
我已经检查过很多次了,这对我来说是不可能的。
Main.cpp
#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
#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
#include <iostream>
#include "add.h"
int function()
{
int a{ 0 };
std::cin >> a;
return a;
}
add.h
#ifndef _IOSTREAM_
#define _IOSTREAM_
int function();
int functionTwo(int a, int b);
#endif
我正在使用Microsoft Visual studio,并且正在尝试编译这段代码。我确保创建了新项目/ .cpp文件和.h文件。我尝试删除了pch.h和pch.cpp文件,但我就是不明白我做错了什么。请帮帮我。我知道,所以我对此感到抱歉。
发布于 2019-03-26 08:48:46
您要做的是添加:
#include "pch.h"
#include "add.h"
因此,在每个使用头文件add.h的文件中,请确保在它上面也使用了pch.h,否则它会告诉您您忘记使用它了,它将无法工作。只需添加#include "pch.h"
就可以解决所有问题。
https://stackoverflow.com/questions/55347824
复制相似问题