[C++ Learning Road] Handling of undeclared identifier errors in cout and cin in VS2015

As follows, if you use the old input and output streams to compile, you will find an error

sample code

[cpp]  view plain   copy
  print ? Check out code snippets on CODE derived to my code slice
  1. #include "stdafx.h"  
  2. #include <iostream.h>  
  3.   
  4. int main(int argc,char* argv[])  
  5. {  
  6.     int a, b, sum;  
  7.     cout << "Please input a:" << endl;  
  8.     cin >> a;  
  9.     cout << "Please input b:" << endl;  
  10.     cin >> b;  
  11.     sum = a + b;  
  12.     cout << "The sum is:" << sum << endl;  
  13.     return 0;  
  14. }  

After compiling, you will find that you are reporting "cout": similar errors for undeclared identifiers

At this time, the following modifications can be made

[cpp]  view plain   copy
  print ? Check out code snippets on CODE derived to my code slice
  1. #include "stdafx.h"  
  2. #include <iostream>  
  3. using namespace std;  
  4.   
  5. int main(int argc,char* argv[])  
  6. {  
  7.     int a, b, sum;  
  8.     cout << "Please input a:" << endl;  
  9.     cin >> a;  
  10.     cout << "Please input b:" << endl;  
  11.     cin >> b;  
  12.     sum = a + b;  
  13.     cout << "The sum is:" << sum << endl;  
  14.     return 0;  
  15. }  

1. Change the #include <iostream.h> non-standard input and output stream to the standard input and output stream of #include <iostream>

2. Add the content in quotation marks "using namespace std;" at the beginning to use the standard namespace

After making the above two modifications, the compilation can pass

Guess you like

Origin blog.csdn.net/hackdjh/article/details/52055639