先上代码

 // 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遇见的奇葩问题的更多相关文章

  1. 控制台console使用MFC库函数,Cout输出CString的方法

    新建工程的时候选择:Win32 Console Application 在向导的地方勾选MFC头文件支持,确认即可 等待初始化文件完成后,VS2010会自动打开 项目名.cpp的文件 其中int _t ...

  2. mybatis遇见的奇葩问题(返回null)

    1.问题描述 select 语句没有问题,执行完毕后通过日志也可以看出 select到数据了,但是拿到的值就是null 2.原因 原来是有人将对象变量命名给改了,导致select到结果后不能映射成为对 ...

  3. 问题解决——cout 输出 CString

    Unicode下 wcout<<strText.GetString()<<endl;

  4. 使用Cout输出String和CString对象

    CString和string都是一个类,不同的是CString主要用于MFC或者是ATL编程中,而string则多用于Windows控制台编程中 在实际编程过程中,我们经常用到string或者是CSt ...

  5. for in 循环的输出顺序问题

    var data = { '4': 'first', '3': 'second', '2': 'third', '1': 'fourth' }; for (var i in data) { conso ...

  6. [nginx]nginx的一个奇葩问题 500 Internal Server Error phpstudy2018 nginx虚拟主机配置 fastadmin常见问题处理

    [nginx]nginx的一个奇葩问题 500 Internal Server Error 解决方案 nginx 一直报500 Internal Server Error 错误,配置是通过phpstu ...

  7. vs中CString的用法,以及所需的头文件

    转载:https://blog.csdn.net/shizhandong50/article/details/13321505 1.CString类型的头文件#include <afx.h> ...

  8. 洛谷 P1118 数字三角形游戏 Label:dfs

    题目描述 有这么一个游戏: 写出一个1-N的排列a[i],然后每次将相邻两个数相加,构成新的序列,再对新序列进行这样的操作,显然每次构成的序列都比上一次的序列长度少1,直到只剩下一个数字位置.下面是一 ...

  9. 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 ...

随机推荐

  1. svn地址如何更改

    1.先进入平时放的更新文件的位置 2.然后右键 选中TortoiseSVN中的Relocate修改里面的完了之后输入账号和密码就好了当然你要记得密码和账号

  2. Logistic Regression 模型简介

    逻辑回归(Logistic Regression)是机器学习中的一种分类模型,由于算法的简单和高效,在实际中应用非常广泛.本文作为美团机器学习InAction系列中的一篇, 主要关注逻辑回归算法的数学 ...

  3. redis运维的一些知识点

    恰好看到一些redis需要主要的东西 记下 供参考 原文地址 http://hi.baidu.com/ywdblog/item/1a8c6ed42edf01866dce3fe3 最近在线上实际使用了一 ...

  4. org.hibernate.PropertyNotFoundException: Could not find a getter for employee in class com.itcast.f_hbm_oneToMany.Department

    <hibernate-mapping package="com.itcast.f_hbm_oneToMany"> <class name="Depart ...

  5. 使用rsync命令提高文件传输效率

    众多数据库服务器的管理过程中,在不同服务器间的文件传输是免不了的.您可以使用scp命令或FTP方法完成文件的发送和接收,这篇文章我将给大家介绍另外一种方法,这就是rsync命令.rsync是文件传输程 ...

  6. 二分 Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) D

    http://codeforces.com/contest/722/problem/D 题目大意:给你一个没有重复元素的Y集合,再给你一个没有重复元素X集合,X集合有如下操作 ①挑选某个元素*2 ②某 ...

  7. C++11 半同步半异步线程池的实现

    #include <list> #include <mutex> #include <thread> #include <condition_variable ...

  8. 一篇非常适合git入门的文章

    http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/00137583770360579 ...

  9. 解决centos无法上传文件和打开文件夹

    使用yum搭建了ftp服务..yum的使用参考:http://blog.csdn.net/enson16855/article/details/9140623 windows使用FileZilla连接 ...

  10. C: define many functions using predefine..

    /* Defines COUNTER. There must be exactly one such definition at file scope * within a program. */ # ...