user1908190
user1908190

Reputation:

cin not working in my code

Error in line 9, 10 and 13 "no operator found which takes a left-hand operand of type 'std:istream' (or there is no acceptable conversion'"

#include <stdafx.h>  // I should have put #include "stdafx.h" instead
#include <iostream>  // My mistake was I didn't #include <string>

using namespace std;
    int main()
{
    cout << "This is the left step bitwise operation\n";
    string x;
    cin >> x;  // line 9
    cout << "You typed" << x;  //line 10
    string y;
    cout << "Enter second number please!"; 
    cin >> y; // line 13
    cin.get();
    return 0;
} // line 

My vague guess is that I didn't #include something

Upvotes: 1

Views: 294

Answers (3)

xxg1413
xxg1413

Reputation: 1

#include "stdafx.h"  
or move 
#include <stdafx.h>
add 
#include <string>

Upvotes: 0

ihsoy ih
ihsoy ih

Reputation: 1028

If you include a file from the same directory do not use angled quotes but use doubled instead.

#include "stdafx.h"

Also, include <string>.

Upvotes: 0

Qaz
Qaz

Reputation: 61970

You forgot to #include <string>. Your code relies on that when you input a string, as well as when you declare it, and when you output it.

#include "stdafx.h"
#include <iostream>
#include <string> <------

I can't take too much credit for this, so it's a community wiki.

Upvotes: 3

Related Questions