用c++从网站上读取文本
Reading text from a website in C++
我目前正在编写一个聊天应用程序之类的东西,它从DropBox上我的"公共"文件夹中的。txt文件中写入和读取。我想知道我究竟如何才能做到这一点。
目前为止我的代码是:
#include <iostream>
#include <fstream>
#include <Windows.h>
#include <cstdlib>
using namespace std;
int main () {
string output;
string outputty;
string Chat;
string option;
string line;
ofstream players;
ifstream chat;
fstream chatw;
cout << "(1) - Entern";
cin >> option;
if (option == "1") {
players.open ("C:/Users/Pebsie/Dropbox/Public/data.txt");
string name;
cout << "nWhat is your name?n";
cin >> name;
players << name;
players.close();
cout << "Entering..";
chatw.open ("C:/Users/Pebsie/Dropbox/Public/chat.txt", fstream::out | fstream::app | fstream::ate);
chatw << "***" << name << " Entered the game*** " << endl;
chatw.close();
while (1) {
system("cls");
ifstream myfile ("C:/Users/Pebsie/Dropbox/Public/chat.txt");
if (myfile.is_open()) {
while ( myfile.good() )
{
getline (myfile,line);
cout << line << endl;
}
myfile.close();
}
cin >> option;
if (option == "/refresh") {
//DO NOTHING
}
else if (option == "/clearchat") {
chatw.open ("C:/Users/Pebsie/Dropbox/Public/chat.txt", fstream::out);
chatw << name << " cleared the chat." << endl;
chatw.close();
}
else {
chatw.open ("C:/Users/Pebsie/Dropbox/Public/chat.txt", fstream::out | fstream::app | fstream::ate);
chatw << name << ": " << option << endl;
chatw.close();
}
}
system("pause");
chatw.open ("C:/Users/Pebsie/Dropbox/Public/chat.txt", fstream::out | fstream::app | fstream::ate);
chatw << "***" << name << " Left the game..*** " << endl;
chatw.close();
return 0;
}
}
当我编写它时,我在本地测试它,但仍然写入它,以便用户可以看到我向它更新了什么。
所以,任何帮助将非常感激,谢谢!
编辑-我的问题是,我实际上如何能够写入和读取dropbox文件。它的公共URL是http://dl.dropbox.com/u/17570838/chat.txt/我如何从在线URL加载文件
p。S:这只是一个测试用的聊天应用,它显然不是很好,因为它不会自动更新。
查看libcurl库。它支持许多文件传输协议,包括HTTP。还有curlpp,它是libcurl的c++包装器。
请参阅相关问题的示例。
通过HTTP读取文件应该相当简单。唉,我不知道Dropbox使用什么机制来上传文件(WebDAV?)
相关文章:
- 将从格式化文本文件读取的文本数据存储到链表
- 读取字符串文本输入以创建 2D 矢量
- 需要从存档中读取一行文本.txt直到找到"hhh",然后转到下一行
- 反转从控制台读取的文本
- 高效读取 3MB 文本文件,包括解析
- C++程序在 freopen 中读取大文本后停止工作
- C++忽略使用字符串流进行读取的文本文件中的空白
- 读取大量文本/文本文件的更快方法?
- 使用 std::ifstream 读取 ASCII 文本文件C++
- 如何读取从文本文件到几个数组的不同类型的数据?C
- 使用标准C++无线流读取UTF-8文本并转换为UTF-16
- 从二进制文件中抓取文本时,为什么 xdg_vtnr=8 是我的结果
- 视觉读取列文本数据并在C++中放入 3D 数组
- C++在同一函数中读取各种文本文件
- 从进程内存中读取的文本块中丢弃解析的行
- 读取长文本文件时程序崩溃 - "*.exe has stopped working"
- IO:从一个C++程序和另一个Java程序同时写入和读取同一个文本文件
- OpenCV,在显示图像时读取用户文本输入(使用 waitKey)
- 如何逐行枚举从文件中读取的文本,并找到 C 中字符和单词最多的行
- P/Invoke in ASP.NET (从 dll 读取/写入文本文件)