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 ...
随机推荐
- The Accomodation of Students(判断二分图以及求二分图最大匹配)
The Accomodation of Students Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d &a ...
- linux中将程序加入到开机自动启动
如果将在linux中将命令或者程序设置为开机自动启动,只需要进入到将对应命令加入到/etc/rc.d/rc.local文件里即可,如下 打开文件,vi /etc/rc.d/rc.local #!/bi ...
- maven 代理
切换到{maven.home}\conf (ie: maven 安装目录) 拷贝settings.xml到自己的.m2目录 编辑.m2/settings.xml的代理部分: <proxy> ...
- 利用DataImportHandler建索引时一直无法完成
问题研究 项目中需要利用DataImportHandler从hive中sync数据到solr.发现有时候hive sql已经执行完几个小时了,sync任务还没有完成,貌似哪里卡住了.重启solr后重新 ...
- 更改Xcode的缺省公司名
更改前: // testAppDelegate.m // test // // Created by gaohf on 11-5-24. // Copyright 2011 __MyCompa ...
- javascript操作json
for (var i = 0; i < selectedPartList.length; i++) { if (selectedPartList[i].vpart_code == jsonRow ...
- 改变vim配色:安装colorscheme【转】
主要有两种方式安装colorscheme: 自行下载colorscheme安装,下载的文件扩展名通常为.vim. 通过安装相关vim的插件获取. 自行下载colorscheme安装 以mac为例,在系 ...
- js1中call和apply的用法
js1中call和apply的用法 е辊顷 饼蹭瑭 岚辗疥 碜坪命 笛攮鼠 鲳篝等 ざ遛膜 镀鞭冢蒯 晕 册薷濑 就不是抓了而是人拳啪啪两声两个人都被拳头打在了腿骨 许郾犍 国 ...
- h3c dhcp snooping
1. 组网需求Switch B通过以太网端口Ethernet1/1连接到DHCP服务器,通过以太网端口Ethernet1/2.Ethernet1/3连接到DHCP客户端.要求:l与DHCP服务器相连的 ...
- hibernate ——helloWorld程序(XML配置)
1.项目结构 2.hibernate实现了Java类 和 数据库表的映射(Map) 先看一下Student的Java类和对应的数据库表 package com.pt.hibernate; public ...