4 Replies - 404 Views - Last Post: 20 August 2019 - 11:35 PM Rate Topic: -----

#1 SC0TTii   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 17-August 19

Cout is ambiguous?

Posted 20 August 2019 - 11:15 AM

So I am just messing around with 2D arrays, but i'm getting the error that "cout is ambiguous"? Nothing looks wrong with my code but I can't figure out what is causing that error. All help is appreciated.

#include <iostream> //input output stream
#include <iomanip> //input output manipulation
#include <limits> //limits for data types
#include <string> // //std::string, std::stoi
using namespace std; //using standard namespace

int main() {

	//WORKING WITH SIZEOF AND ARRAYS
	
	string aArray[2][3] = {
		{"dog", "cat", "moose"},
		{"deer", "parrot", "dolphin"}
	};

	cout << sizeof(string) << endl;

	return 0;
	
}


Is This A Good Question/Topic? 0
  • +

Replies To: Cout is ambiguous?

#2 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5454
  • View blog
  • Posts: 14,402
  • Joined: 18-April 07

Re: Cout is ambiguous?

Posted 20 August 2019 - 12:33 PM

What compiler are you using? If you are using some IDE like visual studio or something, make sure no other libraries are being included automatically.

I have run your code through three different online compilers and all have run successfully with no errors about cout.

This leads me to believe that you are having a library included automatically or cout some how is getting overloaded and the compiler doesn't know which version of cout to use. The one from library A or the one from library B (which may be the library automatically getting included)
Was This Post Helpful? 1
  • +
  • -

#3 SC0TTii   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 17-August 19

Re: Cout is ambiguous?

Posted 20 August 2019 - 12:42 PM

I am using Visual Studio's compiler, but I apparently seemed to have fixed the problem by removing "#include <string>".
I'm a beginner at C++ so I don't really know why this fixed it, but it did...?
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15215
  • View blog
  • Posts: 60,898
  • Joined: 12-June 08

Re: Cout is ambiguous?

Posted 20 August 2019 - 12:54 PM

If you are using Visual Studios it helps to have this line at the very top.

#include "stdafx.h"


https://docs.microso...es?view=vs-2019
http://www.cplusplus...icles/1TUq5Di1/
Was This Post Helpful? 1
  • +
  • -

#5 albert003   User is offline

  • D.I.C Addict

Reputation: 36
  • View blog
  • Posts: 739
  • Joined: 15-December 14

Re: Cout is ambiguous?

Posted 20 August 2019 - 11:35 PM

I'm using the ide code blocks and I don't get that error message and it runs perfectly.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1