stdafx.h我在Visual Studio 2010中启动项目时会自动生成一个名为的文件.我需要创建一个跨平台的C++库,所以我不能/不能使用这个头文件.
什么stdafx.h用于?我可以删除这个头文件吗?
cross-platform visual-studio-2010 stdafx.h visual-studio visual-c++
我目前正在使用" 自学C++ 21天,第二版"一书来学习C++编码,以及Microsoft Visual C++ 2010 Express.在第1章的最后,有一个关于编写和编译以下代码的小练习:
#include <iostream>
int main ()
{
cout << "Hello World!\n";
return 0;
}
Run Code Online (Sandbox Code Playgroud)
很简单吧?但令我惊讶的是,由于此错误,代码无法编译:
错误C2065:'cout':未声明的标识符
我开始淘网,并很快找到了一些解决方案在这里.原来我必须添加
using namespace std;到我的代码!
但是书中没有提到命名空间,所以我认为这本书已经过时了.(它使用#include <iostream.h>预处理器指令!)一些网络研究后,我发现了很多关于命名空间的信息,namespace std与一些历史背景以及<iostream.h>和<iostream>,以及新信息的所有这种流动是相当混乱给我.(更不用说关于医疗性病的所有不必要的Google结果......)
所以这里有一些我到目前为止的问题:
iostream图书馆,为什么namespace需要找到cout?是否有另一个cout可能导致名称冲突的地方?如果有人可以为此提供图表,那就太好了.作为奖励,一些历史背景:
iostream.h它改变之前到底是什么iostream?
没有namespace起到这种变化的一部分?
我正在尝试编译下面的简单程序.但是,它没有编译并给出错误:
error C2065: 'cout' : undeclared identifier
Run Code Online (Sandbox Code Playgroud)
我想问你为什么这个程序不起作用虽然我已经包含iostream头文件了?
#include <iostream>
void function(int) { cout << “function(int) called” << endl; }
void function(unsigned int) { cout << “function(unsigned int) called” << endl; }
int main()
{
function(-2);
function(4);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
提前致谢.
我有一些代码可以让我绘制新月形状,并提取了要绘制的值。然而,有些数字已经到位了-1.#IND。首先,如果有人可以解释这意味着什么,因为谷歌返回了 0 个链接。其次是否有办法阻止它发生。
我的代码有一个简短的类比。除此之外我还有很多代码,但这只是计算角度。
for(int j=0; j<=n; j++)//calculation for angles and output displayed to user
{
Xnew2 = -j*(Y+R1)/n; //calculate x coordinate
Ynew2 = Y*(pow(1-(pow((Xnew2/X),2)),0.5));
if(abs(Ynew2) <= R1)
cout<<"\n("<<Xnew2<<", "<<Ynew2<<")"<<endl;
}
Run Code Online (Sandbox Code Playgroud)
更多信息
我现在遇到这个代码的问题。
for(int i=0; i<=n; i++) //calculation for angles and output displayed to user
{
Xnew = -i*(Y+R1)/n; //calculate x coordinate
Ynew = pow((((Y+R1)*(Y+R1)) - (Xnew*Xnew)), 0.5); //calculate y coordinate
Run Code Online (Sandbox Code Playgroud)
和
for(int j=0; j<=n; j++)//calculation for angles and output displayed to user
{
Xnew2 = -j*(Y+R1)/((n)+((0.00001)*(n==0))); //calculate …Run Code Online (Sandbox Code Playgroud) 在我的main.cpp中,我的所有cout和cin都有错误.
/**
* Description: This program demonstrates a very basic String class. It creates
* a few String objects and sends messages to (i.e., calls methods on)
* those objects.
*
*/
//#include <iostream>
#include "mystring.h"
//using namespace std;
/* Function Prototypes */
void Display(const String &str1, const String &str2, const String &str3);
/*************************** Main Program **************************/
int main()
{
String str1, str2, str3; // Some string objects.
char s[100]; // Used for input.
// Print out their initial values... …Run Code Online (Sandbox Code Playgroud)