1 Replies - 31991 Views - Last Post: 16 February 2011 - 04:27 PM Rate Topic: -----

#1 hussein_236  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 08-January 11

cout is ambiguous ?

Posted 16 February 2011 - 03:59 PM

hello i am trying to write a program, book matching, that writes the names of students that have a book they dont need in a file, and names of people who need books in another, then try to match the people based on the books they have/need, this is the code so far, i haven't done the 'book match' part yet, but it should be able to write the names in the two files

#include "stdafx.h"
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
	char choice0 = '5';
	cout << "1: Add a book(s)\n2: Book Match\nq: quit" << endl; // error here "cout is ambiguous"
	cin >> choice0; // error here "cin is ambiguous"

	while (choice0 != 'q')
	{
		if (choice == '1')
		{
			char choice1 = '5';
			cout << "1: available books\n2: needed books\nd: done" << endl;
			while (choice1 != 'd')
			{
				if (choice1 == '1')
				{
					ofstream file1;
					file1.open ("available books.txt");

					if (!file1)
					{
						cout << "Error opening file" << endl;
					}

					else
					{
						char choice2 = '5';
						while (choice2 != 'd')
						{
							char bookName[50];
							char studentName[50];

							cout << "enter book/course name: ";
							cin >> bookName;
							file1 << bookName;
							cout << "\nenter student name: ";
							cin >> studentName;
							file1 << studentName;
							cout << "\nmore books? press d when done";
							cin >> choice2;
						}
					}
					file1.close();
				}

				else if (choice == '2')
				{
					ofstream file1;
					file1.open ("needed books.txt");

					if (!file1)
					{
						cout << "Error opening file" << endl;
					}

					else
					{
						char choice2 = '5';
						while (choice2 != 'd')
						{
							char bookName[50];
							char studentName[50];

							cout << "enter book/course name: ";
							cin >> bookName;
							file1 << bookName;
							cout << "\nenter student name: ";
							cin >> studentName;
							file1 << studentName << "\n";
							cout << "\nmore books? press d when done";
							cin >> choice2;
						}
					}
					file1.close();
				}
			}
		}
	}
	
	return 0;
}


in lines 9 and 10, the cout and cin are underlined with read and saying "cout is ambiguous" and "cin is ambiguous" how can i fix this?

thanks for any help.

Is This A Good Question/Topic? 0
  • +

Replies To: cout is ambiguous ?

#2 diego_pmc  Icon User is offline

  • D.I.C Addict

Reputation: 81
  • View blog
  • Posts: 565
  • Joined: 13-May 09

Re: cout is ambiguous ?

Posted 16 February 2011 - 04:27 PM

Remove the using namespace std; line and instead of cout and cin use std::cout and std::cin. As a general rule, you shouldn't be having using namespace declarations because, as you can see here, it can confuse the compiler. In time you will understand better exactly why.

This post has been edited by diego_pmc: 16 February 2011 - 04:33 PM

Was This Post Helpful? 3
  • +
  • -

Page 1 of 1