Visual Studio 无法识别标准库

Visual Studio doesn't recognize std library

我正在 Visual Studio 2015 年用 C++ 编写 MFC 应用程序。我添加了一些使用 std 库成员的代码,并假设采用一个 int 并从中创建一个前缀为“0x”的十六进制 char*。我试图从两台不同的计算机在 VS 2015 和 VS 2017 上构建项目,但我遇到了同样的错误——VS 无法识别标准库。我已经将 运行 代码绑定到其他程序 (Clion) 上并且运行良好。

当我包含 #include <stdlib> 时,出现以下错误: cannot open source file "stdlib"

我已经尝试了 re-installing VS,并检查了我是否拥有支持 C++ 的所有必要扩展,但我想仍然缺少一些东西。我该如何解决?

代码:

std::ostringstream ss;
int i = 7;

ss << std::hex << std::showbase << i;
std::string str = ss.str();
const char *output = str.c_str();

std::cout << output << std::endl;

并包括以下 headers:

#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <strstream>

我收到以下错误:

'Ostringstream': is not a member of 'std'
'Ostringstream': undeclared identifier
'ss': undeclared identifier
'hex': is not a member of 'std'
'showbase': is not a member of 'std'
'string': is not a member of 'std'
'string': undeclared identifier

谢谢。

我包含的 headers 顺序错误。在 Visual Studio 中的每个 C++ 项目中,它自动包含 "stdafx.h" 库。该库包含许多常用的库,例如 <string> 等。解决方案是按以下方式编写包含:

#include "stdafx.h"
// other headers of the form "header.h"

#include <cstdlib>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <strstream>
// other headers of the form <header>

而不是:

#include <cstdlib>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <strstream>
// other headers of the form <header>

#include "stdafx.h"
// other headers of the form "header.h"

在此 question

中详细介绍

感谢所有试图提供帮助的人,感谢您的时间和关注。