lee*_*bit 3 c++ standard-library visual-studio-2010 visual-studio
我刚拿到这本书"探索C++",我正在上第一堂课.作为一个爱好,我一直在做C#几年,所以我为什么不尝试C++.
在书中它说我需要设置我的编译器以使用标准C++.我正在使用visual studio 2010,所以我做到了.http://msdn.microsoft.com/en-us/library/ms235629.aspx
但是当我去编译代码时,一切正常,除了一个if语句.
我按照指示进行了三次检查,因此必须使用工具.
特别
if (not in) // this line here
{
std::perror(argv[1]);
return EXIT_FAILURE;
}
Run Code Online (Sandbox Code Playgroud)
完整的样本
#include <algorithm>
#include <fstream>
#include <iostream>
#include <iterator>
#include <ostream>
#include <string>
#include <vector>
void read(std::istream& in, std::vector<std::string>& text)
{
std::string line;
while (std::getline(in, line))
text.push_back(line);
}
int main(int argc, char* argv[])
{
std::vector<std::string> text;
if (argc <2)
read(std::cin, text);
else
{
std::ifstream in(argv[1]);
if (not in)
{
std::perror(argv[1]);
return EXIT_FAILURE;
}
read(in,text);
}
std::sort(text.begin(), text.end());
std::copy(text.begin(), text.end(),
std::ostream_iterator<std::string>(std::cout, "\n"));
}
Run Code Online (Sandbox Code Playgroud)
我真的很想继续阅读这本书,所以非常感谢任何帮助.
如果这对我来说非常无聊,我会道歉.
not是布尔运算符的"替代标记" !.
也许您的编译器不支持它.
试试这个:
if (!in)
Run Code Online (Sandbox Code Playgroud)
实际上,这是另一个网站上完全相同的问题.
VC编译器默认情况下不会识别替代令牌(现在它们非常罕见),但我相信这种支持可以通过编译器开关打开.
实际上,Visual Studio要求您#include <ciso646>获得对替代令牌的支持,即使C++标准声明这应该没有效果1.顽皮的Visual Studio!
无论如何,您可能希望找到更好,更现代的教科书.
我推荐这些资源.
1
[n3290: footnote 176]:特别是,包括标准标题<iso646.h>或<ciso646>没有效果.