使用c ++将图片上传到服务器 [英] Upload pics to a server using c++

查看:169
本文介绍了使用c ++将图片上传到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用C ++将照片上传到我们的服务器,以下是我的测试代码摘录

I'm trying to upload a photo to one of our server in C++, the following is an excerpt of my testing code

//in main
ifstream fin("cloud.jpg");
ofstream fout("cloudcpy.jpg");

string data;
while ( fin )
    fin >> data;
fout << data;
fin.close();
fout.close();

return 0;

但是输出文件不是副本,比原始文件小得多。我的代码有什么问题?

But the output file is not a copy, much more smaller than the original one. Anything wrong in my code?

推荐答案

不能使用字符串作为数据类型。因为JPEG文件不是文本文件。请尝试使用原始类型,如unsigned char或unsigned int来做。

You may not use string as the data type. Since JPEG file is not a textfile. Please try to use primitive type such as unsigned char or unsigned int to do it.

这篇关于使用c ++将图片上传到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆