如何使cout在页面满后停止输出文本?
How do I make cout stop outputting text after the page is full?
我使用winsock2做了一个简单的web浏览器,我有它从服务器的响应,但它发送总和21000字节,我需要能够复制和粘贴html, javascript, css等测试我所做的gui。它总是填满终端,我看不到它从哪里开始,我只是在一堆javascript中间结束。我希望它像在cmd中那样停止并询问您是否要继续。
#include <windows.h>
#include <winsock2.h>
#include <conio.h>
#include <stdio.h>
#include <iostream>
using namespace std;
#define SCK_VERSION2 0x0202
#define DEFAULT_BUFLEN 21000
#define DEFAULT_PORT 27015
namespace Globals{
string input = "";
char recvbuf[DEFAULT_BUFLEN];
const char* carf = recvbuf;
}
using namespace Globals;
HWND staticText2 = CreateWindowEx(WS_EX_PALETTEWINDOW, TEXT("Static"), TEXT("Email"), /* email */
WS_CHILD | WS_VISIBLE, 122, 80, 44, 20,
/*hwnd*/NULL, NULL, NULL, NULL);
int sck() {
//----------------------
// Declare and initialize variables.
WSADATA wsaData;
int iResult;
SOCKET ConnectSocket = INVALID_SOCKET;
struct sockaddr_in clientService;
char name[500] = "";
char ipADDRESS[500] = "";
char sPORT[500] = "";
sockaddr_in sName;
int sNameSize = sizeof(sName);
char const* sendbuf = "GET /?gws_rd=ssl HTTP/1.1rn"
"Host: www.google.com:80rn"
"User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.30729)rn"
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8rn"
"Accept-Language: en-us,en;q=0.5rn"
//"Accept-Encoding: gzip,deflatern"
"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7rn"
"Keep-Alive: 300rn"
"Connection: keep-alivern"
"Pragma: no-cachern"
"DNT: 1"
"Cookie:
"Cookie:
"Cache-Control: no-cachernrn";
char recvbuf[DEFAULT_BUFLEN];
int recvbuflen = DEFAULT_BUFLEN; //23.214.132.132 GoDaddy.com
int WSAERROR = WSAGetLastError(); //190.93.243.15
//system("color 04"); //172.16.100.114 Mrs.Hall
//----------------------
// Initialize Winsock
iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
if (iResult != NO_ERROR) {
printf("WSAStartup failed: %dn", iResult);
return 1;
}
//----------------------
// Create a SOCKET for connecting to server
ConnectSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (ConnectSocket == INVALID_SOCKET) {
printf("Error at socket(): %in", WSAGetLastError() );
WSACleanup();
return 1;
}
//----------------------
// The sockaddr_in structure specifies the address family,
// IP address, and port of the server to be connected to.
printf("IP ADDRESS: 74.125.196.191 is Google 216.58.208.37 is mail.google.com 129.66.24.10 is iNown");
cin >> ipADDRESS;
printf("PORT: n");
cin >> sPORT;
//system("color 04");
u_short PORT = strtoul(sPORT, NULL, 0);
clientService.sin_family = AF_INET;
clientService.sin_addr.s_addr = inet_addr(ipADDRESS); //74.125.196.191
clientService.sin_port = htons(PORT); //135: msrpc, 445: microsoft-ds, 554: rtsp, 1025: NFS-or-IIS, 1026: LSA-or-nterm
//1027: IIS, 1028: uknown, 1029: ms-lsa, 139: weird behavior
//----------------------
// Connect to server.
iResult = connect( ConnectSocket, (SOCKADDR*) &clientService, sizeof(clientService) );
if ( iResult == SOCKET_ERROR) {
closesocket (ConnectSocket);
printf("Unable to connect to server: %in", WSAGetLastError());
WSACleanup();
return 1;
}
//----------------------
//Get local host name
iResult = gethostname(name, sizeof(name));
if (iResult == NO_ERROR) {
printf("Host Name: %sn", name);
}
else if (iResult == SOCKET_ERROR) {
printf("Could not resolve host name: %i", WSAGetLastError());
}
//------------------------
//Get peer name
iResult = getpeername(ConnectSocket, (struct sockaddr*)&sName, &sNameSize);
if (iResult == NO_ERROR)
printf("Peer Name: %sn", inet_ntoa(sName.sin_addr));
else if (iResult == SOCKET_ERROR)
printf("Could not get peer name: %in", WSAGetLastError());
//-------------------------
// Send an initial buffer
iResult = send( ConnectSocket, sendbuf, (int)strlen(sendbuf), 0 );
if (iResult == SOCKET_ERROR) {
printf("send failed: %dn", WSAGetLastError());
closesocket(ConnectSocket);
WSACleanup();
return 1;
}
else
printf("Bytes Sent: %in", iResult);
//-----------------------------
// shutdown the connection since no more data will be sent
iResult = shutdown(ConnectSocket, SD_SEND);
if (iResult == SOCKET_ERROR) {
printf("shutdown failed: %dn", WSAGetLastError());
closesocket(ConnectSocket);
WSACleanup();
return 1;
}
// Receive until the peer closes the connection
do {
iResult = recv(ConnectSocket, recvbuf, recvbuflen, 0);
if ( iResult > 0 ) {
printf("Bytes received: %dn", iResult);
cout << "From Server" << recvbuf << endl;//printf("From server: %sn", recvbuf);
}
else if ( iResult == 0 )
printf("Connection closedn");
else if (WSAERROR == WSAETIMEDOUT)
printf("recv failed: WSAETIMEDOUTn");
} while( iResult > 0 );
// cleanup
closesocket(ConnectSocket);
WSACleanup();
system("PAUSE");
return 0;
}
int main() {
sck();
MessageBox(NULL, "Successful", "Result:", MB_OK);
}
这是我的代码
刚刚意识到我所要做的就是去网页,并将cookie更改为我使用EditThisCookie插件在我的程序中所做的,然后复制源代码。XD
相关文章:
- C++ 以相反的顺序输出文本文件
- 如何在不移动C 中的光标坐标的情况下输出文本以控制特定坐标
- 输出文本文件的位置
- 从输入复制到输出文本文件
- 输入和输出文本文件
- 您如何在输出文本的同时接受用户输入
- 如何从随机数中输出文本
- 使用读取系统调用C++输出文本
- 输出文本C++
- 将输出文本与 cout 对齐到右侧
- 如何在不使用cout/printf的情况下输出文本在cpp和c中
- 用户在输出文本时输入到控制台
- C++每x次输出文本
- outFile C++未写入输出文本
- C++:将输出文本格式化为.doc/.docx/.rtf(第2部分)
- 将输出文本格式化为.doc/.docx
- 从长期运行的控制台应用程序(C++)输入和输出文本
- 主函数不输出文本文件行
- 输出文本文件数据到字符数组
- 如何在c++中输出文本到打印机