c++ compile time error

duxfox--

I'm learning c++ and trying some things out... The following code is giving me a compile time error, can anyone explain to me why, I'm a little confused... I'm assuming it's the cin >> playagain statement. Thank you for the help. (also if I'm making any other general c++ mistakes, please let me know)

heres the error:

Error 1 error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) c:\users\abdo\documents\visual studio 2012\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 45 1 ConsoleApplication1

anyways, including #include <string> fixed the problem, thank you 0x499602D2

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

using namespace std;
class calculatorc1 {
public:
    calculatorc1();
    ~calculatorc1();
    int multnums(int a, int b);
protected:
    int result;
};

calculatorc1::calculatorc1() {
}
calculatorc1::~calculatorc1() {
}



int calculatorc1::multnums(int a, int b) {
    int result = a * b;
    return result;
}


int main()
{
    string playagain;
    bool calcing = true;
    while (calcing) {
    calculatorc1 c;
    int x;
    int y;
    cout << "first num\n";
    cin >> x;
    cout << "second\n";
    cin >> y;
    cout << c.multnums(x, y) << "\n";
    cout << "mul again? (y/n)\n";
    cin >> playagain;
    if (playagain == "n") {
        calcing = false;
        system("pause");
    }
    }

}
0x499602D2

I believe the problem is that you're not including the <string> header which is why you're getting a compile-time error because string has not been defined in the program. You're going to need this line to fix that problem:

#include <string>

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Compile time error in C#

分類Dev

C compile error

分類Dev

C macro evaluate at compile time

分類Dev

C++ metaprogramming - compile time search tree

分類Dev

Is typedef resolved at compile time in c++?

分類Dev

C++ compile error - no match for ‘operator=’

分類Dev

Why instance initialization block is not throwing compile time error for duplicate entry?

分類Dev

Swift: compile-time error with optional chaining and nil-coalescing

分類Dev

Spring Data Mongo with Kotlin error: "must be a compile-time constant"

分類Dev

How to get compile time error checking with real valued function arguments?

分類Dev

Play Framework 2.7.x Compile Time DI Error

分類Dev

ASIO handler arguments and boost::bind, compile time error

分類Dev

How to create compile time check for multiple C++ types?

分類Dev

Initialize a C++ struct like an array of unknown bound at compile time

分類Dev

Choose default type and encoding for C++ string literals at compile time

分類Dev

C# run time error

分類Dev

Implicit conversion at compile time

分類Dev

Compile time hash with constexpr

分類Dev

Force function to return value and make compile error C#

分類Dev

How to fix this compile error for std::chrono comparison in C++11?

分類Dev

java coding:: Eclipse showing Compile time error on Line 4 only why?

分類Dev

Why do I get 'unknown type name DetailViewController' error, only some of the time when I compile?

分類Dev

Time limit exceeded error C++

分類Dev

akka http compile error

分類Dev

Asset Catalog Compile Error

分類Dev

Streams backport compile error

分類Dev

Why is this not giving a compile error

分類Dev

Execute compile time-compiled regex at compile time

分類Dev

Do C++ compilers perform compile-time optimizations on lambda closures?

Related 関連記事

  1. 1

    Compile time error in C#

  2. 2

    C compile error

  3. 3

    C macro evaluate at compile time

  4. 4

    C++ metaprogramming - compile time search tree

  5. 5

    Is typedef resolved at compile time in c++?

  6. 6

    C++ compile error - no match for ‘operator=’

  7. 7

    Why instance initialization block is not throwing compile time error for duplicate entry?

  8. 8

    Swift: compile-time error with optional chaining and nil-coalescing

  9. 9

    Spring Data Mongo with Kotlin error: "must be a compile-time constant"

  10. 10

    How to get compile time error checking with real valued function arguments?

  11. 11

    Play Framework 2.7.x Compile Time DI Error

  12. 12

    ASIO handler arguments and boost::bind, compile time error

  13. 13

    How to create compile time check for multiple C++ types?

  14. 14

    Initialize a C++ struct like an array of unknown bound at compile time

  15. 15

    Choose default type and encoding for C++ string literals at compile time

  16. 16

    C# run time error

  17. 17

    Implicit conversion at compile time

  18. 18

    Compile time hash with constexpr

  19. 19

    Force function to return value and make compile error C#

  20. 20

    How to fix this compile error for std::chrono comparison in C++11?

  21. 21

    java coding:: Eclipse showing Compile time error on Line 4 only why?

  22. 22

    Why do I get 'unknown type name DetailViewController' error, only some of the time when I compile?

  23. 23

    Time limit exceeded error C++

  24. 24

    akka http compile error

  25. 25

    Asset Catalog Compile Error

  26. 26

    Streams backport compile error

  27. 27

    Why is this not giving a compile error

  28. 28

    Execute compile time-compiled regex at compile time

  29. 29

    Do C++ compilers perform compile-time optimizations on lambda closures?

ホットタグ

アーカイブ