Ошибка cout не является однозначным

Программа по вычислениям полностью устраивает, она перемножает 2 матрицы указанного размера с рандомными числами, она запускается и правильно считает, но показывает, что есть ошибки типа: c...

Программа по вычислениям полностью устраивает, она перемножает 2 матрицы указанного размера с рандомными числами, она запускается и правильно считает, но показывает, что есть ошибки типа: cin, cout, system не являются однозначными, всего 17 ошибок, подчеркивает красным эти операторы, как это убрать?

#include <iostream>
#include <ctime>
#include <iomanip>
using namespace std;
int main()
{
setlocale(LC_ALL, "Russian");
int** P1, ** P2, ** P3, n, m;
cout << "Введите кол-во строк матрицы: ";
cin >> n;
cout << "Введите кол-во столбцов матрицы: ";
cin >> m;
P1 = new int* [n];
for (int i = 0; i < n; i++)
    P1[i] = new int[m];
srand(time(0));
for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)  //рандом 1 матрицы
        P1[i][j] = rand() % 10;
for (int i = 0; i < n; i++)
{
    cout << endl;                  //вывод 1 матрицы
    for (int j = 0; j < m; j++)
    {
        cout << setw(3) << P1[i][j] << "t";
    }
}
cout << endl;
int k;
cout << "Введите кол-во столбцов 2 матрицы: ";
cin >> k;
P2 = new int* [k];
for (int i = 0; i < m; i++)
    P2[i] = new int[k];
for (int i = 0; i < m; i++)
    for (int j = 0; j < k; j++)  //рандом 2 матрицы
        P2[i][j] = rand() % 10;
for (int i = 0; i < m; i++)
{
    cout << endl;                  //вывод 2 матрицы
    for (int j = 0; j < k; j++)
    {
        cout << setw(3) << P2[i][j] << "t";
    }
}
cout << endl;
P3 = new int* [n];
for (int i = 0; i < n; i++)
    P3[i] = new int[k];
for (int i = 0; i < n; i++)
{
    for (int j = 0; j < k; j++)  //умножение матриц
    {
        P3[i][j] = 0;
        for (int z = 0; z < m; z++)
            P3[i][j] = P3[i][j] + P1[i][z] * P2[z][j];
    }
}
cout << endl << "Результат умножения:" << endl;
for (int i = 0; i < n; i++)                     //вывод результата 
 умножения
{
    cout << endl;
    for (int j = 0; j < k; j++)
        cout << setw(3) << P3[i][j] << "t";
}
cout << endl;
for (int i = 0; i < n; i++)
    delete[] P1[i];
delete[] P1;
for (int i = 0; i < m; i++)
    delete[] P2[i];
delete[] P2;
for (int i = 0; i < n; i++)
    delete[] P3 [i];
delete[] P3;
system("pause");
return 0;
}

1 / 1 / 4

Регистрация: 01.10.2016

Сообщений: 247

1

15.06.2017, 20:47. Показов 68977. Ответов 1


Добрый день, при написании кода я столкнулся с проблемой, cout везде выбивает «
«cout» не является однозначным С++», как решить эту проблему?

Условие : «С помощью перегруженных функций реализуем задачу для различных типов массивов, например для типов int и float. «
Код:

C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "stdafx.h"
#include <stdio.h>
#include <conio.h>
#include <iostream>
 
using namespace std;
//-------------------------------------
void Init_mas(int m, float *x)// перегруженная функция
{
  cout<<"Введите массив:n";
  for(int i=0;i<n;i++) {
   cout<<"a[“<<i<<”] = "; cin>>x[i];
  }
}
//-------------------------------------
void Init_mas(int m, int *x)
{
  cout<<"Введите массив:n";
  for(int i=0;i<n;i++) {
   cout<<"a[“<<i<<”] = "; cin>>x[i];
  }
}
//-------------------------------------
int Nomer_el(int m, float *x) // перегруженная функция
{
 int k=0; //номер минимального элемента
 float min= x[0];
 for(i=0;i<m;i++){
   if(x[i]<min){ k=i; min=x[i]}
 }
 return k;
}
//------------------------------------
int Nomer_el(int m, int *x){
 int k=0; //номер минимального элемента
 float min= x[0];
 for(i=0;i<m;i++){
   if(x[i]<min){ k=i; min=x[i]}
 }
 return k;
}
//------------------------------------
float Summa_el(int m, float *x)// перегруженная функция
{
 float s=0; //сумма
 for(i=0;i<m;i++) {
    if((i%2)==0)s+=a[i];
 }
 return s;
}
//--------------------------------------
int Summa_el(int m, int *x)
{
 float s=0; //сумма
 for(i=0;i<m;i++)
 {
    if((i%2)==0)s+=a[i];
 }
 return s;
}
//----------------------------------------
int main() {
   cout <<"Для массива вещественного типа "<<endl;
  float *a;
  int n; 
  cout<<"Введите длину массива: "; cin>>n;
  a=new float[n]; //создание динамического массива
  Init_mas(n,a);
int m=0; //номер минимального элемента
  float s=0; //сумма
  m = Nomer_el(n,a);  s = Summa_el(n,a);
  for(i=0;i<n;i++){
   if(a[i]<0.0){
    for(int j=i;j<n-1;j++)a[j]=a[j+1];
    a[j] = 0;
}
   }
   cout<<"1)номер минимального элемента массива: ";
  cout<<m<<endl;
  cout<<"2)сумма элементов с четными номерами: "
  cout<<s<<endl;
  cout<<"nСжатие массива и вывод на экран.n";
  for(i=0;i<n;i++) printf("a[%d] = %5.2fn",i,a[i]);
  delete(a); //уничтожение массива
}
// тоже самое для массива целого типа
 {
  cout <<"Теперь для массива целого типа "<<endl;
  int *a, n; clrscr();
  cout<<"Введите длину массива: "; cin>>n;
  a=new int[n]; //создание динамического массива
  Init_mas(n,a);
  int m=0; //номер минимального элемента
  float s=0; //сумма
  m = Nomer_el(n,a); s = Summa_el(n,a);
0){
    for(int j=i;j<n-1;j++)a[j]=a[j+1];
    a[j] = 0;
  }
 }
  cout<<"1)номер минимального элемента массива :"
 cout<<m<<endl;
  cout<<"2) сумма элементов с четными номерами : "
cout<<s<<endl;
  cout<<"nСжатие массива и вывод на экран.n";
   for(i=0;i<n;i++) printf("a[%d] = %5.2fn",i,a[i]);
  delete(a); //уничтожение массива
 }
 getch();
 return 0;
}

__________________
Помощь в написании контрольных, курсовых и дипломных работ, диссертаций здесь



0



  • Forum
  • General C++ Programming
  • Cout is ambiguous?

Cout is ambiguous?

What does that mean? How do I fix it?

Post the actual error message, as well as the line of code which is causing the error.

Post your code so that it is [code]between code tags[/code] as this will give it syntax highlighting and line numbers.

Please copy and paste the exact error message, and indicate which line the error is talking about.

Last edited on

Well, I am working on this bank database project and whenever I post this part:

void addaccount()
{
ifstream inData;
ofstream outData;
string fileName;
string str;
cout << «Insert the name of the data file: «;
cin >> fileName;
inData.open(fileName); // Access the file of the name you had inputted
string lastName, firstName, type;
double balance;
inData >> lastName >> firstName >> balance >> type;
cout << «What file would you like to save the data in?: «;
cin >> fileName;
outData.open(fileName);
outData << str;
cout << «nEnter the customer’s last name:»;
cin >> lastName;
cout << «nnEnter the customer’s first name : «;
cin >> firstName;
cin.ignore();
cin.getline(50, firstName);
cout << «nEnter Type of The account (C/S) : «;
cin >> type;
type = toupper(type);
cout << «nEnter The Initial amount(>=500 for Saving and >=1000 for current ) : «;
cin >> deposit;
cout << «nnnAccount Created.»;
}

void deleteaccount();
{
account ac;
ifstream inFile;
ofstream outFile;
inFile.open(«account.dat», ios::binary);
if (!inFile)
{
cout << «File could not be open !! Press any Key…»;
return;
}
outFile.open(«Temp.dat», ios::binary);
inFile.seekg(0, ios::beg);
while (inFile.read(reinterpret_cast<char *> (&ac), sizeof(account)))
{
if (ac.retacno() != n)
{
outFile.write(reinterpret_cast<char *> (&ac), sizeof(account));
}
}
inFile.close();
outFile.close();
remove(«account.txt»);
rename(«Temp.txt», «account.txt»);
cout << «nntRecord Deleted ..»;
}

void search();
{
int seqSearch(const int list[], int listLength, int searchItem)
{
int loc;
bool found = false;

for (loc = 0; loc < listLength; loc++)
if (list[loc] == searchItem)
{
found = true;
break;
}
if (found)
return loc;
else
return -1;
}

into it, all the couts get the error message IntelliSense: «cout» is ambiguous.

Speaking of which, I really need help with that. I have a topic called ‘Bank Database’ I could really use help with.

IntelliSense errors aren’t compilation errors. Sometimes IntelliSense can get confused or out of date.

Go to Build -> Rebuild

You may also consider trying to prefix your ‘cout’ object with its namespace, ‘std’. In other words, wherever you’ve put

cout << "Information";

You may consider putting

std::cout << "Information";

Perhaps there are multiple objects called ‘cout’ in your program (or you’ve included external libraries which also have a cout object) and providing a namespace might give some clarification as to which one you mean.

Topic archived. No new replies allowed.

Понравилась статья? Поделить с друзьями:

Читайте также:

  • Ошибка couldn t load xpcom
  • Ошибка could not retrieve architectures from server rufus как исправить
  • Ошибка could not launch game
  • Ошибка could not instantiate mail function
  • Ошибка could not find the data directory we cannot run 1004 spore

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии