Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all articles
Browse latest Browse all 3021

Compiler error with cout object

$
0
0
Hello, I am asp.net C# developer. I decided to tackle C++, so I started today. This is probably something simple I am sure but I cannot figure out what the problem is. I would appreciate if someone could show me what is wrong and why.

Code:

        srand(static_cast<unsigned int>(time(0)));
        int choice = rand() % NUM_WORDS;
        string theWord = WORDS[choice][WORD];
        string theHint = WORDS[choice][HINT];

        string jumble = theWord;
        int length = jumble.size();
        for(int i = 0; i < length;i++)
        {
                int index1 = (rand() % length);
                int index2 = (rand() % length);

                char temp = jumble[index1];
                jumble[index1] = jumble[index2];
                jumble[index2] = temp;
        }

        cout << "\t\t\tWelcome to Word Jumble!\n\n";
        cout << "Unscramble the letters to make a word.\n";
        cout << "Enter 'hint' for a hint.\n";
        cout << "Enter 'quit' to quit the game.\n\n";
        cout << "The jumble is: " << jumble;

The error is happening on the last output operator, just before the jumble variable on the last line.The error is:

Code:

  Intellisense: no operator"<<" matches these operands
operand types are: std::basic_ostream<char, std::char_traits<char> <<std::string

I understand what its saying, but jumble is a std::string

Here are my preprocessor directives and using statements
Code:

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

using namespace std;

Thanks in advance!

Viewing all articles
Browse latest Browse all 3021

Trending Articles