【发布时间】:2011-09-11 18:29:51
【问题描述】:
我刚拿到这本书“探索 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;
}
完整样本
#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"));
}
我真的很想继续阅读这本书,因此非常感谢任何帮助。
如果这对我来说非常愚蠢,我深表歉意。
【问题讨论】:
-
根据这篇文章stackoverflow.com/questions/555505/c-alternative-tokens 你应该使用 /Za 开关来禁用扩展。
标签: c++ visual-studio visual-studio-2010 standard-library