我刚拿到这本书"探索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, …Run Code Online (Sandbox Code Playgroud)