Erroe code E1696 in line #include <stdafx.h>

jonathanSch 1 Reputation point
2021-04-14T10:45:29.203+00:00

Im building a Arduino project. Only in the last few days have I started registering C ++. I'm trying to create software that reads a line from a file that will send through serial port or bluetooth. This is what I was able to collect from the internet.

#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <stdafx.h>

//using namespace System;
//using namespace System::IO::Ports;

 int main()
{
    //SerialPort port("COM9", 9600);
    //port.Open();

     std::ifstream file("scan.txt");
     std::vector<std::string>names;
     std::string input;

     while (file >> input)
     {
         names.push_back(input);
     }

    for (std::string name : names)
    {
         std::cout << name << std::endl;
         //port.Write(name);
    }

     return 0;

}

The lines that are notice causing me problems I think it has to do with the line #include <stdafx.h>. When I try to run the code I get the error E1696 "cannot open source file "stdafx.h""
I tried all of these possibilities
Im using Visual Studio 2019 onn win 10 machine.

Developer technologies | C++
Developer technologies | C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Viorel 125.7K Reputation points
    2021-04-14T11:07:43.907+00:00

    If for some reasons you do not want to use "Precompiled Headers" (or do no know how), then remove the '#include <stdafx.h>' line.


  2. Guido Franzke 2,191 Reputation points
    2021-04-15T10:12:43.457+00:00

    Hello,

    as already said, the file stdafx.h is used for precompiled headers. In most projects of Visual Studio it is standard that the file is created automatically.

    It looks like you created your project in another way. Now you want to use a source file that includes stdax.h.

    The easiest way to solve your problem is: create an empty text file in your project directory and rename it to "stdafx.h".

    Regards, Guido


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.