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 |
#include <iostream> #include <Windows.h> #include <string> using namespace std; #define DLL_LOAD_ERR -1 int (*lenght)(char* s); int (*Sravnenie) (char s1[], char s2[]); void (*unity)(char* s1, char* s2); void (*del)(char* s, int st, int leng, char* fin); void (*Copy)(char* s, int st, int leng, char* fin); int (*search)(char* s1, char* s2); int (*strsearch)(char* s1, char* s2); int (*lenfin)(char* s); HMODULE LibInst; int OpenDLL() { LibInst = LoadLibraryA("C:\\VS2017\\C++\\Library\\DLL_Library\\STRLibrary"); if (LibInst) { lenght = (int(*)(char * s)) GetProcAddress(LibInst, "lenght"); Sravnenie = (int(*)(char s1[], char s2[])) GetProcAddress(LibInst, "Sravnenie"); unity = (void(*)(char* s1, char* s2)) GetProcAddress(LibInst, "unity"); del = (void(*)(char* s, int st, int leng, char* fin)) GetProcAddress(LibInst, "del"); Copy = (void(*)(char* s, int st, int leng, char* fin)) GetProcAddress(LibInst, "Copy"); return 0; }; return DLL_LOAD_ERR; } void CloseDLL() { FreeLibrary(LibInst); } int main() { std::cout << "Hello World!\n"; if (OpenDLL() == 0) { SetConsoleCP(1251); SetConsoleOutputCP(1251); int st, len; char finstr[100]; char s1[100]; char s2[100]; char s3[100]; char s4[100]; cout << "Введите строку 1: "; cin.getline(s1, 50); cout << "Введите строку 2: "; cin.getline(s2, 50); cout << "Длина первой строки:" << endl; cout << lenght(s1) << endl; cout << "Сравнение строк:" << endl; cout << Sravnenie(s1, s2) << endl; cout << "Соединение строк:" << endl; cout << unity(s1, s2) << endl; //отсутствует оператор "<<", соответствующий этим операндам cout << "введите позицию удаляемой части:" << endl; cin >> st; cout << "Введите длину удаляемой части:" << endl; cin >> len; cout << "Результат удаления:" << endl; cout << del(s1, st, len, finstr) << endl; //отсутствует оператор "<<", соответствующий этим операндам cout << "введите позицию копирования:" << endl; cin >> st; cout << "Введите длину копирования части:" << endl; cin >> len; cout << "Результат копирования:" << endl; cout << Copy(s1, st, len, finstr) << endl; //Ошибка (активно) E0349 отсутствует оператор "<<", соответствующий этим операндам |
Пишу программу на С++, в которой надо разработать определения двух классов COne и CTwo, которые связаны отношением включения. Проблема возникает в мейне, при попытке вывести A.getObj()
.
Сама ошибка : 0349 отсутствует оператор «<<«, соответствующий этим операндам
Скорее всего ошибка возникает из-за того, что в классе отсутствует нужный метод. Помогите с его реализацией, пожалуйста
//MAIN
#include <iostream>
#include <String.h>
#include "CTwo.h"
#include "COne.h"
using namespace std;
int main()
{
CTwo A("CTwo String","COne String", 505);
A.Print();
cout << A.getS() << endl;
cout << A.getObj() << endl; // <==== ошибка тут
}
//COne.h
#ifndef CONE_H
#define CONE_H
#include <iostream>
#include <string>
using namespace std;
class COne
{
protected:
string s;
double d;
public:
COne();
COne(string S, double D);
~COne();
COne(const COne& arg);
void print();
COne(COne& arg);
const double& getD();
const string& getS();
void Print();
COne& operator=(const COne& arg);
friend class CTwo;
};
#endif
//CTwo.h
#ifndef CTWO_H
#define CTWO_H
#include <iostream>
#include <string>
#include "COne.h"
using namespace std;
class COne;
class CTwo
{
protected:
string s;
COne obj;
public:
CTwo();
CTwo(string S, string SOne, double d);
virtual ~CTwo();
void Print();
const string& getS();
const COne& getObj();
friend class COne;
};
#endif
You are trying to pass the return value of snakeorladder()
to cout << ...
, but snakeorladder()
has a void
return value — ie, it doesn’t return anything at all. So there is nothing to pass to operator<<
.
Simply get rid of the print statement in main()
, especially since snakeorladder()
already prints everything internally:
int main()
{
snakeorladder(place25);
}
Otherwise, you would have to change snakeorladder()
to return something that main()
can actually print, eg:
const char* snakeorladder(int myplace)
{
char L1Top = 0, L1Bot = 0, L2Top = 0, L2Bot = 0, L3Top = 0, L3Bot = 0, S1Top = 0, S1Bot = 0, S2Top = 0, S2Bot = 0, S3Top = 0, S3Bot = 0;
if (L1Top == myplace)
return "L1Top";
if (L1Bot == myplace)
return "L1Bot";
if (L2Top == myplace)
return "L2Top";
if (L2Bot == myplace)
return "L2Bot";
if (L3Top == myplace)
return "L3Top";
if (L3Bot == myplace)
return "L3Bot";
if (S1Top == myplace)
return "S1Top";
if (S1Bot == myplace)
return "S1Bot";
if (S2Top == myplace)
return "S2Top";
if (S2Bot == myplace)
return "S2Bot";
if (S3Top == myplace)
return "S3Top";
if (S3Bot == myplace)
return "S3Bot";
return "";
};
int main()
{
cout << snakeorladder(place25);
}
I have date installed using vcpkg.
#include <iostream>
#include "date/date.h"
int main()
{
auto today = floor<date::days>(std::chrono::system_clock::now());
std::cout << today << '\n';
std::cout << "Hello World!\n";
}
building above code rise the error
E0349 no operator «<<» matches these operands
VS 2019 : version 16.7.0
Standard : ISO C++17 Standard (std:c++17)
Platform Toolset : Visual Studio 2019 (v142)
Unfortunately the streaming operators are in namespace date
instead of namespace std::chrono
. And the type of today
is a std::chrono::time_point
type. This means that you’ll need to manually expose the streaming operators because ADL won’t find them.
The most precise way to do this is:
This also works, and often is already done for other reasons:
When we get this lib in C++20, the streaming operators will be found by ADL in namespace std::chrono
and this step will no longer be necessary.
another problem with this library is that when i place windows.h include directive on top of date/date so many errors arise.
but when i place windows.h include directive below of data/date.h no error arised.
**#include <windows.h>**
#include <iostream>
#include <chrono>
#include "date/tz.h"
#include "date/date.h"
using namespace date;
using namespace std::chrono;
// to move back to the beginning and output again
void gotoxy(int x, int y)
{
COORD coord; // coordinates
coord.X = x; coord.Y = y; // X and Y coordinates
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord); // moves to the coordinates
}
int main()
{
while (true)
{
gotoxy(0, 0);
std::cout << date::zoned_time{ date::current_zone(), std::chrono::system_clock::now() }.get_local_time() << '\n';
}
std::getchar();
}
Severity Code Description Project File Line Suppression State
Error (active) E0070 incomplete type is not allowed DateTimeSamples C:\Dev\vcpkg\installed\x64-windows\include\date\date.h 421
Error (active) E0040 expected an identifier DateTimeSamples C:\Dev\vcpkg\installed\x64-windows\include\date\date.h 421
Error C2059 syntax error: '(' DateTimeSamples C:\Dev\vcpkg\installed\x64-windows\include\date\date.h 421
Error C2143 syntax error: missing ',' before '?' DateTimeSamples C:\Dev\vcpkg\installed\x64-windows\include\date\date.h 421
Error C2535 'date::year::year(void)': member function already defined or declared DateTimeSamples C:\Dev\vcpkg\installed\x64-windows\include\date\date.h 421
Error C2059 syntax error: '?' DateTimeSamples C:\Dev\vcpkg\installed\x64-windows\include\date\date.h 421
Error C2059 syntax error: 'noexcept' DateTimeSamples C:\Dev\vcpkg\installed\x64-windows\include\date\date.h 421
Error C2334 unexpected token(s) preceding '{'; skipping apparent function body DateTimeSamples C:\Dev\vcpkg\installed\x64-windows\include\date\date.h 421
Error C2059 syntax error: '(' DateTimeSamples C:\Dev\vcpkg\installed\x64-windows\include\date\date.h 422
Error C2143 syntax error: missing ',' before '?' DateTimeSamples C:\Dev\vcpkg\installed\x64-windows\include\date\date.h 422
Error C2535 'date::year::year(void)': member function already defined or declared DateTimeSamples C:\Dev\vcpkg\installed\x64-windows\include\date\date.h 422
Error C2059 syntax error: '?' DateTimeSamples C:\Dev\vcpkg\installed\x64-windows\include\date\date.h 422
Error C2059 syntax error: 'noexcept' DateTimeSamples C:\Dev\vcpkg\installed\x64-windows\include\date\date.h 422
Error C2334 unexpected token(s) preceding '{'; skipping apparent function body DateTimeSamples C:\Dev\vcpkg\installed\x64-windows\include\date\date.h 422
Error C2589 '(': illegal token on right side of '::' DateTimeSamples C:\Dev\vcpkg\installed\x64-windows\include\date\date.h 1169
Error C2059 syntax error: '(' DateTimeSamples C:\Dev\vcpkg\installed\x64-windows\include\date\date.h 1169
Error C2589 '(': illegal token on right side of '::' DateTimeSamples C:\Dev\vcpkg\installed\x64-windows\include\date\date.h 1630
Error C2062 type 'unknown-type' unexpected DateTimeSamples C:\Dev\vcpkg\installed\x64-windows\include\date\date.h 1630
Error C2059 syntax error: ')' DateTimeSamples C:\Dev\vcpkg\installed\x64-windows\include\date\date.h 1630
Error C3615 constexpr function 'date::year::ok' cannot result in a constant expression DateTimeSamples C:\Dev\vcpkg\installed\x64-windows\include\date\date.h 1628
Error C2589 '(': illegal token on right side of '::' DateTimeSamples C:\Dev\vcpkg\installed\x64-windows\include\date\date.h 6106
Error C2760 syntax error: unexpected token '(', expected ')' DateTimeSamples C:\Dev\vcpkg\installed\x64-windows\include\date\date.h 6106
Error C2589 '(': illegal token on right side of '::' DateTimeSamples C:\Dev\vcpkg\installed\x64-windows\include\date\date.h 6327
Define NOMINMAX
to disable the Windows min
and max
macros.
Adding #include helps for this problem when a string used by cout or cin
#include <iostream>
#include <string>
#include <vector>
#include <stdlib.h>
#include <cstring>
#include <list>
using namespace std;
int main()
{
char message[] = "Привет мир";
char alphabet[] = { '&', 'а', 'м', 'Й', 'ю', '4', 'p', '=', 'F', '7', 'Ц', 'H', 'a', 'O', 'Ш', 'R', 'Л', 'M', 'з', 'I', 'о', '!', 'Н', '2', 'j', '5', 'Ж', '6', '0', 'Ю', 'ч', 'C', 'm', 'З', 'в', '+', '1', 'u', 'G', 'Z', '#', 'т', 'c', '.', 'э', 'e', '3', 'х', 'у', 'Y', 'd', 'D', 'Д', '%', 'й', 'r', 'Q', 'д', 'щ', 'N', '-', 'V', 'y', 'С', 'Ч', 'Б', '8', 'К', 'X', 'T', '9', 'b', 'S', '$', 'М', 'A', 'L', 'q', 'Р', '@', 'р', 'У', 'ё', 'E', 'Ф', '~', 'л', 'О', 'и', 'Х', 't', 'ж', 'k', 'w', 'f', 'Э', 'е', 'П', 'B', 'И', 'Ё', '?', ',', 'ц', 'v', 'ш', 'б', 's', 'н', 'l', 'g', 'А', 'Т', 'я', 'n', 'J', 'K', 'h', 'В', 'x', 'i', 'с', 'U', 'W', 'п', 'к', 'P', 'ф', 'Е', 'z', 'o', 'г' };
int key = 1;// GetRandomNumber(0, 16);
list<char> result;
for (int index = 0; index < strlen(message); index++)
{
char elem = message[index];
if (index + key > size(alphabet) + 1)
{
index = index + key - size(alphabet);
}
else
{
index = index + key;
}
result.push_back(alphabet[index]);
}
cout << result;
}
Ошибка (активно) E0349 отсутствует оператор «<<«, соответствующий этим операндам 31 строка
Как пофиксить эту ошибку и вывести список?