C++ 输出Cstring遇见的奇葩问题
先上代码
// webConteng.cpp : Defines the entry point for the console application.
// #include "stdafx.h"
#include <stdlib.h>
#include <afxinet.h>
#include <iostream>
#include <fstream>
using namespace std; int main(int argc, char* argv[])
{
printf("Hello World!\n");
/////////////////////////////////////////////
CInternetSession session("HttpClient");
char * url = "http://www.baidu.com";
CHttpFile *pfile = (CHttpFile *)session.OpenURL(url); DWORD dwStatusCode;
pfile->QueryInfoStatusCode(dwStatusCode);
if(dwStatusCode == HTTP_STATUS_OK)
{
CString content;
CString data;
ofstream o_file;
o_file.open("11.txt");
while (pfile->ReadString(data))
{
content += data + "\r\n";
char* test=data.GetBuffer(data.GetLength());
o_file << test <<endl;
}
o_file.close();
content.TrimRight();
printf(" %s\n ", content);
}
pfile->Close();
delete pfile;
session.Close();
////////////////////////////////////////////////////////
system("pause");
return ;
}
如果不将data赋值给test,而是直接输出data就会出现很奇葩的问题,输出的全是八位的数字
只要将data转为 char*就OK了;
坑死我一个多小时的时间。。。
C++ 输出Cstring遇见的奇葩问题的更多相关文章
- 控制台console使用MFC库函数,Cout输出CString的方法
新建工程的时候选择:Win32 Console Application 在向导的地方勾选MFC头文件支持,确认即可 等待初始化文件完成后,VS2010会自动打开 项目名.cpp的文件 其中int _t ...
- mybatis遇见的奇葩问题(返回null)
1.问题描述 select 语句没有问题,执行完毕后通过日志也可以看出 select到数据了,但是拿到的值就是null 2.原因 原来是有人将对象变量命名给改了,导致select到结果后不能映射成为对 ...
- 问题解决——cout 输出 CString
Unicode下 wcout<<strText.GetString()<<endl;
- 使用Cout输出String和CString对象
CString和string都是一个类,不同的是CString主要用于MFC或者是ATL编程中,而string则多用于Windows控制台编程中 在实际编程过程中,我们经常用到string或者是CSt ...
- for in 循环的输出顺序问题
var data = { '4': 'first', '3': 'second', '2': 'third', '1': 'fourth' }; for (var i in data) { conso ...
- [nginx]nginx的一个奇葩问题 500 Internal Server Error phpstudy2018 nginx虚拟主机配置 fastadmin常见问题处理
[nginx]nginx的一个奇葩问题 500 Internal Server Error 解决方案 nginx 一直报500 Internal Server Error 错误,配置是通过phpstu ...
- vs中CString的用法,以及所需的头文件
转载:https://blog.csdn.net/shizhandong50/article/details/13321505 1.CString类型的头文件#include <afx.h> ...
- 洛谷 P1118 数字三角形游戏 Label:dfs
题目描述 有这么一个游戏: 写出一个1-N的排列a[i],然后每次将相邻两个数相加,构成新的序列,再对新序列进行这样的操作,显然每次构成的序列都比上一次的序列长度少1,直到只剩下一个数字位置.下面是一 ...
- P1118 [USACO06FEB]数字三角形Backward Digit Su…
题目描述 FJ and his cows enjoy playing a mental game. They write down the numbers from 1 to N (1 <= N ...
随机推荐
- AutoTile 自动拼接 番外篇(自动融合技术)
http://pan.baidu.com/s/1dDQyfSl 密码:ttud 先睹为快吧. 之后 还差一个 智能替换 技术.
- 算法入门(C++)
iostream,这个头文件里有很多常用的函数,比如swap交换两个变量的值,max求两个值的最大值等. cstdio头文件,这个头文件里包含C风格的输入输出.如果你之前学习过C++语言应该知道cin ...
- MFC中为菜单或按钮添加快捷键功能
1.新建一快捷键资源,ACCELERATOR,关联相应的ID号,下图所示中,其中,第一个ID为自定义快捷键ID,按CTRL+R,此时响应该ID以应的消息响应函数, 第二个ID为菜单ID,此时按CTRL ...
- how to add a shared lib in C?
http://www.cprogramming.com/tutorial/shared-libraries-linux-gcc.html Basically, 2 steps: 1) make the ...
- 遭遇mediumint上限
Mediumint:The signed range is -8388608 to 8388607. The unsigned range is 0 to 16777215. home_notific ...
- 终于购入Mac mini,发现HDMI接口与显示器不兼容,网购了一个VGA转换插头
Mac mini买到了,最便宜的i5,$647,足够了. 发现路边捡的显示器没有HDMI接口,所以在学校图书馆问了一下IT 技术支持,给我推荐了ebay上$10块钱的转换器. 名字叫 Mini Dis ...
- linux安装tomcat, jdk出现的问题
1)卸载系统自带的jdk版本: 查看自带的jdk: #rpm -qa|grep gcj 可能看到如下类似的信息: libgcj-4.1.2-44.el5 jav ...
- javase swing
package com.test; import java.awt.BorderLayout; import java.awt.Color; import java.awt.event.ActionE ...
- PHP的curl实现get,post 和 cookie
类似于dreamhost这类主机服务商,是显示fopen的使用 的.使用php的curl可以实现支持FTP.FTPS.HTTP HTPPS SCP SFTP TFTP TELNET DICT FILE ...
- ExceL转PDF
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Excel = ...