I have C++ compiler issues on Visual Studio 2013. I am learning C++ for the C++ 11 standard and I was given this program that compiles perfectly on every other C++ 11 compiler.
VS 2013 however is giving me issue. It tells me Error: identifier "not" is undefined
(where it says // line 36
in code). I am not sure how to fix this. I have tried to check macros and I am still having issues getting to compile:
/// Sort the standard input alphabetically.
/* Read lines of text, sort them, and print the results to the standard output.
If the command line names a file, read from that file. Otherwise, read from
the standard input. The entire input is stored in memory, so don’t try
this with input files that exceed available RAM.
*/
#include <algorithm>
#include <fstream>
#include <iostream>
#include <iterator>
#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[])
{
// Part 1. Read the entire input into text. If the command line names a file,
// read that file. Otherwise, read the standard input.
std::vector<std::string> text; ///< Store the lines of text here
if (argc < 2)
read(std::cin, text);
else
{
std::ifstream in(argv[1]);
//line 36
if (not in)
{
std::perror(argv[1]);
return EXIT_FAILURE;
}
read(in, text);
}
// Part 2. Sort the text.
std::sort(text.begin(), text.end());
// Part 3. Print the sorted text.
std::copy(text.begin(), text.end(),
std::ostream_iterator<std::string>(std::cout, "\n"));
}