-1

In short i'm not sure if this question has been asked before but the research I did turned up nothing. I am currently teaching myself c++ and thought it would be neat to create some sort of username and password login (I only have structure for the password due to the code issue) to what will become an ssh into-able program running on a AWS server. Based on research I've done it seems that I should be doing something like this

#include <string>
#include <string.h>
#include "pch.h"
#include <iostream>
using namespace std;
int main()
{
    string input;

    cout << "Enter PW" << endl;
    cin >> input;
    cout << input << "was what you set" << endl;

}

Obviously in the end it will not echo back a password and i'm sure this isn't the most secure way to handle things. Every time I try to compile and run the code in Microsoft Visual Studio IDE it gives me two errors which take me to the

cin >> input; 

and the

cout << input << "was what you set" << endl;

Error:  C2679   binary '>>': no operator found which takes a right-hand 
operand of type 'std::string' (or there is no acceptable conversion)    

Error   C2679   binary '<<': no operator found which takes a right-hand 
operand of type 'std::string' (or there is no acceptable conversion)    

https://i.stack.imgur.com/qcpXJ.png This is a console application in IDE the photo above should contain all the code and errors as well. Any help would be greatly appreciated, from what I can tell the issue only appears when I use the string variable. If i'm doing things completely wrong fell free to tell me.

Cheers!

  • 1
    pch.h must come first. Everything before it is ignored. The include of `string`, for all intents and purposes, doesn't exist. – user4581301 Feb 02 '19 at 06:36
  • 1
    Waffling on closing on this since the name of the header has changed, but it explains the problem and a bit of the whys and wherefores. [Purpose of stdafx.h](https://stackoverflow.com/questions/2976035/purpose-of-stdafx-h) – user4581301 Feb 02 '19 at 06:40
  • @user4581301 That definitely looks related, but it isn't quite the same question. But maybe there's another question about `#include`s before stdafx being ignored? –  Feb 02 '19 at 06:48
  • @user4581301 Thanks for the help, never realized that pch.h had to come first, it fixed the issue. – CanadianBacon Feb 02 '19 at 06:50
  • @duskwuff There has to be by now, but Google doesn't come up with anything better in the first few pages. [This](https://stackoverflow.com/questions/16040689/why-stdfax-h-should-be-the-first-include-on-mfc-applications) is a bit more direct, but also misses. – user4581301 Feb 02 '19 at 06:55
  • @user4581301 Maybe [StdAfx + Header file - Order of inclusion in MFC application](https://stackoverflow.com/questions/3090473/stdafx-header-file-order-of-inclusion-in-mfc-application)? –  Feb 02 '19 at 06:55
  • Here's a another good candidate: [What is “pch.h” and why is it needed to be included as the first header file?](https://stackoverflow.com/questions/54121917/what-is-pch-h-and-why-is-it-needed-to-be-included-as-the-first-header-file) Doesn't answer why it pch.h has to go first, I'm starting to wonder if anyone does know, but it's quite explicit that it *must* be first. – user4581301 Feb 02 '19 at 07:11

1 Answers1

0

you have missed .h in iostream and conio.h

#include <string.h>
#include "pch.h"
#include <iostream.h>
#include <conio.h>
using namespace std;
int main()
{
    string input;

    cout << "Enter PW" << endl;
    cin >> input;
    cout << input << "was what you set" << endl;

}
  • 1
    `` is not a C++ header. It isn't even a C header on any modern system. `` isn't a C or C++ header either. –  Feb 02 '19 at 06:40
  • conio.h is there by mistake but the iostream.h is there by default – CanadianBacon Feb 02 '19 at 06:42
  • 2
    You seem to be familiar with Turbo C++. Turbo C++ predates Standardized C++ and might as well be considered a different, but related, language. It does not apply here. – user4581301 Feb 02 '19 at 06:42
  • @duskwuff it should be a header, that's what I was taught in my college. – Shashi Dharan Krish Feb 02 '19 at 06:43
  • @ShashiDharanKrish What you were taught was incorrect. It may have been correct for Turbo C++ (as user4581301 mentioned), but that compiler has been obsolete since the mid-1990s. –  Feb 02 '19 at 06:45
  • @duskwuff Oh, is it!. I was talking with context of Turbo C++. thanks for the information – Shashi Dharan Krish Feb 02 '19 at 06:47
  • @ShashiDharanKrish Right. And that is not a context that you should ever assume unless it's already been mentioned -- Turbo C++ is not used, and in fact _cannot_ be used, for any modern software development. The dialect of C++ it implemented is significantly different from what is used today. –  Feb 02 '19 at 06:50
  • @duskwuff Hmm alright. – Shashi Dharan Krish Feb 02 '19 at 06:52
  • Unfortunately the stack editor is correcting certain lines in editing automatically, but this is being developed in visual C++ not turbo, I don't even think the IDE compiler would handle it – CanadianBacon Feb 02 '19 at 07:14