I used it inside Arduino <iostream>but it doesn't work

I can‘t run it

#include<iostream>
#include<stdlib.h>
#include<time.h>
#include<stdio.h>
#include<winsock2.h>
#include<conio.h>
#include<fstream>
#include <ctime >
using namespace std;
#pragma comment(lib,"ws2_32.1ib")   //使用winsock
#define QLEN 5
#define WSVERS MAKEWORD(2,0)
char buf[2000];
const int BUF_SIZE=64;
int dooropen;  
//延时函数
void Delay(int time)   //time*1000为秒数
{
Clock_t now=clock();
while (clock()-now<time);
}
//客户端类
class tcptoar
{
public
int stat();                //初始化函数
int talker(int a) ;        //传输函数
~tcptoar();                //析构函数
private:
WSADATA   wsd;            //WSADATA变量
SOCKET    sHost ;        //服务器套接字
SOCKADDR_INservAddr;     //服务器地址
char     buf[BUF_SIZE];  //接收数据缓冲区
char     bufRecv[BUF_SIZE]; 
Int      retVal;        //返回值

int tcptoar::stat() {
//初始化套接字动态库
if (WSAStartup(MAKEWORD(2, 2),&wsd)!=0){
Cout<<"WSAStartup failed!"<<endl;
return- 1;
}
//创建套接字
sHost=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if (INVALID_SOCKET == sHost)
{
cout<<"socket failed!"<< end1;
WSACleanup(); //释放套接字资源
return-1;
}
//设置服务器地址
servAddr.sin_family= AF_ INET ;
servAddr.sin_addr.s_addr= inet_addr("172.20.10.8") ;//更改为ESP8266的IP地址servAddr.sin_port=htons((short)8080);//开放端口号
int nServAddlen=sizeof(servAddr);
//连接服务器
retVal = connect(sHost, (LPSOCKADDR)&servAddr,sizeof(servAddr));
if (retVal==SOCKET ERROR)
{
Cout<<"connect failed!",<<end1;
closesocket(sHost);   //关闭套接字
WSACleanup();        //释放套接字资源
return-1 ;
}
return 0;
}
int tcptoar::talker(int a) {
ZeroMemory(bufRecv,BUF_SIZE); //清空bufRecv中的内容
do{
recv(sHost,bufRecv,7,0); //接收ESP8266客户端发送的数据
cout << bufRecv << end1;
} while (buf[0]==0);
Delay(5000);
if (!a) {  //通过a控制是否发送数据
char sendBuf[2500];
ZeroMemory(bufRecv, 2500);
strcpy( sendBuf,"err");
retVal = send( sHost,sendBuf,strlen(buf)0) ;//发送数据并查看返回状态
if (retVal ==SOCKET_ERROR)
{
Cout<< "send failed!"<<endl;
closesocket( sHost) ;//关闭套接字
WSACleanup();    //释放套接字资源
return-1 ;
}
}
else
char sendBuf[2500];
strcpy(sendBuf,"ok");
retValsend( sHost,sendBuf,strlen(buf)0):
if (retVal==SOCKET_ERROR)
{
cout<< "send failed!"<<endl; //关闭套接字
closesocket(sHost); //释放套接字资源
WSACleanup();
return -1;
}}}
tcptoar::~tcptoar() {  //关闭套接字

//退出         //释放套接字资源
closesocket(sHost);
WSACleanup();
}
//TCP服务器
class TCPse
{
public:
TCPset();//构造函数
int statrlisten();//打开监听
int talk();//通信函数
int getIP();//返回本机IP值
void answer(int a,int count) ;//对客户端的返回值
void close();//关闭客户端
private:
WSADATA    wsd;//WSADATA变量
SOCKET     sServer;//服务器套接字
SOCKET     sClient;//客户端套接字
SOCKADDR_IN  addrServ;;//服务器地址
char     sendBuf[BUF SIZE];//返回给客户端的数据
int  retVal//返回值
sockaddr_in  addrClient;
int     addrClient;
};
TCPset::TCPset()
{
if (WSAStartup(MAKEWORD(2,2),&wsd)!=0)
cout<< "WSAStartup failed!"<end1;
sServer = socket(AF_INETSOCK STREAM,IPPROTO_TCP);//打开套接字
if (INVALID_SOCKET==sServer)
{
cout<< "socket failed!"<< endl;
WSACleanup ();//释放套接字资源
}
}
int TCPset::statrlisten() {
addrServ.sin_family= AF_INET;
addrServ.sin_port=htons(4999);//服务器端口号为 4999
addrServ.sin_addr. s_addr= INADDR_ANY;
//绑定套接字
retVal = bind( sServer(LPSOCKADDR) &addrServ,sizeof(SOCKADDR_IN));
/打开客户端
if (retVal == SOCKET_ERROR)
{
cout<< "bind failed!"<< end1;
closesocket(sServer);//关闭套接字
WSACleanup();//释放套接字资源
return- 1;
}
retval = listen(sServer,1);
if (retVal ==SOCKET_ERROR)
{
cout<< "listen failed!"<< end1;
closesocket(sServer);//关闭套接字
WSACleanup();//释放套接字资源
return -1;
}
sockaddr_in addrClient;
int addrClientlen = sizeof(addrClient);
sClient=accept(sServer, (sockaddr FAR * )&addrClient,&addrClientlen);
if (INVALID_SOCKET==sClient)
{
cout << "accept failed!"<< endl;
closesocket(sServer);//关闭套接字
WSACleanup( );//释放套接字资源
return- 1 ;
}
return 0;
}
int TCPset::talk() {
time_tt=time(0);
char tmp[64];
do {
ZeroMemory (buf,BUF_SIZE);//ZeroMemory只是将指定的内存块清零
retVal = recv(sClient, bufBUF_SIZE,0):
if (retVal == SOCKET_ERROR){
Cout<<"recive error" << endl;
return - 1 ;
}
if (buf[0]!='0')
strftime(tmp,sizeof(tmp),"%Y %m %d %X %A本年第%j天",localtime(&t));
cout<<tmp<<"接收的密码为"<<buf<<end1;//输出接收的密码与接收时间
}while (buf[0]=='0');
int TCPset::getIp() {
char szText[256];
int iret ;
iret = gethostname( szText,256) ;//输出本机IP并返回是否成功
int a= WSAGetLastError();
if (iret!=0){
cout<< "Get IP failed"<<endl;
Return -1;
}
HOSTENT*host = gethostbyname(szText);
if (NULL == host)
{
printf("gethostbyname() Failed!");
return false;
}
in_addr PcAddr;
for(int i= 0;;i++)
{
char * p=host->h_addr1ist[i];
if (NULL== p)
{
break;
}
memcpy(&(PcAddr.S_un.S_ addr), Phost->h_length);
char * szIP =::inet_ntoa(PcAddr);
cout<<"Local IP is:"<<IP<<end1;
}
}
void TCPset::answer(int a, int count)
{
dooropen=0;
int sizel;
sizel= sizeof(sendBuf);
if (a){
//定义第几次输出错误,选择返回的数据类型
char buff[64];
switch (count) {
case 3:
strcpy( sendBuf,"密码错误请重新输人密码,剩余两次机会");
case 2:
strcpy( sendBuf,"密码错误请重新输入密码,剩余一次机会");
case 1:
strcpy sendBuf,"密码错误无法打开");
break;
}
send(sClient, sendBuf, strlen(sendBuf),0);
ZeroMemory( sendBuf, size1);
}
else {
strcpy(sendBuf,"密码正确开门中");
send(sClient, sendBuf, strlen(sendBuf),0);
ZeroMemory( sendBuf, size1);
dooropen=1;
}
}
void TCPset:: close(){
closesocket( sServer);//关闭套接字
closesocket(sClient);//关闭套接字
WSACleanup();//释放套接字资源;
}
void main(){
do {
TCPset myTCP;//建立服务器
myTCP.getIP();//返回本机IP
myTCP.statrlisten();//开始监听
int charge =1;//密码是否正确
int count=3;//剩余次数
char password[20000]={ "123456789");//开门密码
do {
myTCP.talk();
cout <<buf << endl;
if (!strcmp(buf, password))
charge=0;
myTCP.answer(charge, count);
count--;
}while ((charge > 0) && count);
myTCP.close();//关闭服务器
tcptoar tcptoarduino;//建立客户端
tcptoarduino.stat();
tcptoarduino.talker(dooropen) ;
}while(1);
}
#include<SoftwareSerial. h>
#define WIFI_TX  2
#define WIFI_RX  3
#define LED 6
SoftwareSerial wifi(WIFI_RX,WIFI_TX);
String wifistate="";
String tcpstate="";
String wifitcp="";
void recatch(int delaytime) {
while(wifi.available()>0)
{
wifistate += char(wifi. read( ));
delay(2);
if (wifistate.length() > 0)
{
Serial. println(wifistate);
wifistate = "";
}
delay(delaytime);
}
void setup(){
pinMode(LED,OUTPUT);
Serial.begin(9600);
wifi.begin(9600); //测试
wifi.print("AT\rln");
recatch(1000) ;
wifi.println("AT+ CWMODE=3");//控制链接模式
recatch(1000);
wii. println("AT+ CWJAP="Pingl"\"@123456zzm\"");
recatch(10000);
recatch(1000);
wifi.println("AT+ CIPMUX =1");
recatch(1000);
wifi.println("AT + CIPSERVER= 1,8080");//打开服务器并定义服务端口
recatch(1000);
wifi.println("AT+ CIFSR);
recatch(1000);
}
void loop(){
Do{
delay(1000);
while (wifi. available()> 0)
{
tcpstate+=char(wifi.read());
delay(2)
}
if (tcpstate.length()>0)
{
Serial.println(tepstate);
}
}while(tcpstate =="Link");
tcpstate ="";
do{
delay(1000);
while(wifi.available()>0)
{
wifitcp += char(wifi.read());
delay(2);
}
if(wifitcp. length()>0)
{
Serial.println(wifitcp);
delay(1000);
}
}while(wifitcp=="");
if(wifitcp[11]=='a')
{
digitalWrite(LED, HIGH);
Serial.println("OK1");
delay(1000);
}
if(wifitcp[11]=='b'){
digitalWrite(LED, LOW);
Serial.println("OK1");
delay(1000);
}
delay(10);
Serial.println(wifitcp[11]);
wifitcp="";
}
#include <Servo.h>
#define PIN_SERVO 10
Servo myservo;
void setup()
{
myservo.attach(PIN_SERVO);
}
void loop()
{
myservo.write(0);delay(1000);
myservo.write(90);delay(1000);
myservo.write(180)delay(1000);
myservo.write(90);delay(1000);
myservo.write(0);delay(1000);
}
#include <Servo.h>
#define PIN_ SERVO 10
Servo myservo ;
char numdata= 0;
void setup() {
myservo.attach(PIN SERVO);
Serial.begin(9600) ;
while(Serial.read()>=0){}
}
void loop(){
int angle;
if(Serial.available()>0){
delay(100);
numdata =Serial. read();
Serial. print("Serial. readBytes:");
Serial. println((int)nundata);
myservo.write((int)numdata);
delay(1000);
myservo.write(0) ;
}
}
}
#include <SoftwareSerial. h>
#include<Enerlib.h>
#include <Servo. h>   //声明调用Servo.h库
#define WIFI TX 2    //ESP8266的读写引脚
#define WIFI RX 3
#define LED 6   //指示灯
#define LED2 5  //报警灯
Energy energy; //电源控制
Servo myservo; //创建一个舵机对象
SoftwareSerial wifi(WIFI_RX,WIFI_TX);
String wifistate="";
String tcpstate="";
void warning() {  //报警函数
for (int i=0;i<100;i++)
{
digitalWrite(LED2,HIGH);
delay(100);
digitalwrite(LED2,HIGH);
}
}
void recatch(int delaytime) {   //返回获取函数
Whil4(wifi.available()>0)
{
wifistate += char(wifi.read());
delay(2);
}
if (wifistate.length() > 0)

{
Serialprintln(wifistate);
wifistate="";
}
//每收到一次数据LED闪烁一次
digitalwrite (LED, HIGH);
delay(100);
digitalwrite(LED,LOW);
delay(delaytime);
}
//当每次有设备连接时,对连接来的客户端返回welcome
void connectstate() {
Serial. println("new connect");
String wificonnect="";
wifi.println("AT+ CIPSTATUS");//查看ESP8266连接状态
while (wifi.available()>0)
{
wificonnect+= char(wifi.read( ));
delay(2);
}
if (wificonnect.length()>0)
{
Serial.println(wificonnect);
}
char num=wificonnect[22];
Serial.println(num);
if (num=='3')
{
char client=wificonnect[36];
Serial.println(client);
String sendtext="AT+ CIPSEND=2,8"; //发送语句
sendtext[11]=client;
Serial.println(sendtext) ;
wifi.println(sendtext);
String text;
while(wifi.available() > 0)
{
text+=char(wifi.read()) ;
delay(2);
}
if (text.length()> 0)
{
Serial.println(text) ;
text="";
}
wifi.println("welcome");
while (wifi.available() > 0)
{
text +=char(wifi.read());
delay(2);
}
if (text.length()>0)
{
Serial.println(text);
text ="";
}
}
wificonnect="";
delay(1000);
void setup() {
pinMode(LED,OUTPUT);//初始化指示灯
pinMode(LED2,OUTPUT);//初始化报警灯
myservo. attach(9);//初始化舱机
Serial.begin(9600);//打开串口
wifi.begin(9600);//打开BSP8266软串口
wifi.print("AT\r\n");//测试
recatch(1000);
Wifi.println("AT+ CWMODE=3");//控制链接模式
recatch(1000);
wifi.println("AT+ CWJAP=\"Ping\",\"@123456zzm\ "");//连接
delay(10000);
//recatch(10000);
recatch(1000);
wifi.println("AT+ CIPMUX=1");//打开ESP8266的连接
recatch(1000);
wifi. println("AT+CIPSERVER=1, 8080");//打开服务器并定义服务端口
recatch(1000);
wifi.println("AT+CIESR");//查看ESPB266的IP
recatch(1000);
}
static int state_1=0;
void loop() {
//ESP8266接收状态判定
while(wifi.available()> 0)
{
tcpstate += char(wifi.read());
delay(2);
}
if(tcpstate.length()>0)
{
Serial.println(tcpstate);
}
delay(1000);
if(tcpstate[0]=='L'&&tcpstate!=""){//判定接收数据是否为连接
connectstate();
Serial.println("new connect");
State_1=1;  //连接状态改为1,连接状态
delay(1000);
}
else if(tcpstate[0]=='U'){//判定接收数据是否为无连接  
Serial. println(tcpstate);
state_1=0;//改变连接状态为无连接状态
}
if (tcpstate[3]== 'I'&&"state_1==1) {//如果在连接状态下接收到数据
if(tcpstate[12]=='o')//如果为OK,打开门
{
myservo.write(180);
delay(10000);
myservo.write(0);
Serial.println( "OK1〞);
delay(1000);
}
if(tcpstate[12]='e') {//如果为error,则调用警报函数并进入睡眠
warning();
Serial.println( "OK2");
Serial.println("Go to sleep...");
energy.PowerDown();
delay(1000);
}
delay(1000);
}
tcpstate="";//清空接收数据
}


C:\Users\80454\Downloads\daima\daima.ino:1:9: fatal error: iostream: No such file or directory
#include
^~~~~~~~~~
compilation terminated.
exit status 1

Compilation error: iostream: No such file or directory

you probably copied a code not meant for your arduino

Your provided code appears to be a badly typed or OCR'd mish mash of a Windows program and an actual Arduino sketch.

ChatGPT??

Wouldn't be my first guess in this case, but it's possible. I just noticed the occasional 1 instead of a lower case l, missing " at the end of string or two, extraneous spaces, missing spaces, the lack of indentation, that kind of thing. Like OCR that was almost, but not quite right, and then just copied and pasted from wherever it came from without noticing that they'd gotten two different bits of source code, not one.

sorry,I have find my wrong, I'll probably have to recheck this, thank you for your advice.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.