cstring

C - How to read a string line by line?

狂风中的少年 提交于 2019-12-07 02:17:41
问题 In my C program, I have a string that I want to process one line at a time, ideally by saving each line into another string, doing what I want with said string, and then repeating. I have no idea how this would be accomplished, though. I was thinking of using sscanf. Is there a "read pointer" present in sscanf like there would be if I was reading from a file? What would be another alternative for doing this? 回答1: Here's an example of how you can do it efficiently, if you are allowed to write

C++中关于string类型究竟能不能用cout输出的问题

泪湿孤枕 提交于 2019-12-07 00:10:21
今天在visual studio 学习c++的string类,发现string的不能用c++的cout函数来输出,后来查了下网上的资料发现应该是可以的,最后才发现自己没有进行导入c++的默认的string的头文件,所以它默认的使用cout不可以使用,编译时出现这样一个错误: error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conversion) 答案:首先得说这个问题的答案是肯定的,cout重载了string类型,所以在c++ 中可以直接输出。 先来看CString、string和string.h这几个区别: CSting: CString是MFC或者ATL中的实现,是MFC里面封装的一个关于字符串处理的功能很强大的类,只有支持MFC的工程才可以使用。如在linux上的工程就不能用CString了,只能用标准C++中的string类了。在MFC中使用不需要自己加,但在另外的程序中需要加入#include<CString>。

CString,Char*,string 互相转换(转)

醉酒当歌 提交于 2019-12-06 09:21:57
《C++标准函数库》中说的 有三个函数可以将字符串的内容转换为字符数组和C—string 1.data(),返回没有”\0“的字符串数组 2,c_str(),返回有”\0“的字符串数组 3,copy() ................................................................. int 转 CString: CString.Format("%d",int); ............................... string 转 CString CString.format("%s", string.c_str()); 用c_str()确实比data()要好. ....................................... char* 转 CString CString.format("%s", char*); CString strtest; char * charpoint; charpoint="give string a value"; strtest=charpoint; //直接付值 ................................................................... CString 转 int CString ss="1212.12";

Error: Conversion to non-scalar type

Deadly 提交于 2019-12-06 05:36:06
I am making a set of derived classes for an assignment. I am instructed to use char arrays (c-strings). When I compile I keep getting the error: Homework11.cpp: In function âint main()â: Homework11.cpp:72: error: conversion from âchar [10]â to non-scalar type âBusinessâ requested Homework11.cpp:73: error: conversion from âchar [10]â to non-scalar type âBusinessâ requested Homework11.cpp:74: error: conversion from âchar [10]â to non-scalar type âAccountâ requested Homework11.cpp:75: error: conversion from âchar [10]â to non-scalar type âAccountâ requested I am fairly certain that my problem is

Heap corruption when deleting a string

戏子无情 提交于 2019-12-06 04:46:27
Here is my code: std::string readString() { int strLen = Read<int>(); char* rawString = new char[strLen]; Read(rawString, strLen); rawString[strLen] = '\0'; std::string retVal(rawString); delete [] rawString; return retVal; } The first line reads the length of the string. The second line creates a new char array (c-string) with the string length The third line reads the string (its reading it from a file) The 4th line adds a NULL to the end. The 5th line creates an std::string out of the c-string. The 6th line deletes the c-string (HEAP CORRUPTION HAPPENS HERE) The 7th line returns the string,

CString to LPCTSTR conversion

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-05 20:01:41
问题 I have a CString variable that i a need to convert to LPCTSTR(const char*) .I need this conversion so that i can use it as an argument in a function . The CString look like : CString sqlTemp = _T("INSERT INTO "+ sw1 +" (filename, "+ sw2 +") VALUE ("+ sw7 +","+ sw3 +" ) "); It contains an query. The prototype of the function is : int WriteBlob(LPCTSTR szSqlStat, LPCTSTR szFilePath) So could you show me an exemple of how to convert to LPCTSTR ? It may be trivial but i am a c++ beginner and i

MFC CFileDialog 相对路径

丶灬走出姿态 提交于 2019-12-05 19:22:37
1)在mfc中想按照自己设定的路径来打开fileDialog,其实CFileDialog有自己的变量 m_ofn,该变量为OPENFILENAME的结构体,用户可自己定义一些内容 例如 打开窗体的名字: dlg.m_ofn.lpstrTitle = _T("遥测图片加载"); 按照自己设定的路径打开dlg: dlg.m_ofn.lpstrInitialDir = _T("C:\\Documents and Settings\\Administrator\\桌面\\2012.4.16\\DrawProgram1\\YCPicture"); 在这里想说的是,使用相对路径 dlg.m_ofn.lpstrInitialDir = _T("res\\YCPicture"); 总体代码如下: CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,_T("图片文件(*.bmp;*.jpg;*.gif)|*.bmp;*.jpg;*.gif| 位图文件 (*.bmp)|*.bmp"),NULL); //dlg.m_ofn.lpstrInitialDir = _T("C:\\Documents and Settings\\Administrator\\桌面\\2012.4.16\\DrawProgram1\

MFC使用ADO连接SQLServer数据库

。_饼干妹妹 提交于 2019-12-05 17:05:32
VC用ADO访问数据库全攻略,介绍了VC用ADO来访问数据库的各个对象及各方法,很经典,也很实用,很值得一看。 正文 一、ADO概述 ADO是Microsoft为最新和最强大的数据访问范例 OLE DB 而设计的,是一个便于使用的应用程序层接口。ADO 使您能够编写应用程序以通过 OLE. DB 提供者访问和操作数据库服务器中的数据。ADO 最主要的优点是易于使用、速度快、内存支出少和磁盘遗迹小。ADO 在关键的应用方案中使用最少的网络流量,并且在前端和数据源之间使用最少的层数,所有这些都是为了提供轻量、高性能的接口。之所以称为 ADO,是用了一个比较熟悉的暗喻,OLE 自动化接口。 OLE DB是一组”组件对象模型”(COM) 接口,是新的数据库低层接口,它封装了ODBC的功能,并以统一的方式访问存储在不同信息源中的数据。OLE DB是Microsoft UDA(Universal Data Access)策略的技术基础。OLE DB 为任何数据源提供了高性能的访问,这些数据源包括关系和非关系数据库、电子邮件和文件系统、文本和图形、自定义业务对象等等。也就是说,OLE DB 并不局限于 ISAM、Jet 甚至关系数据源,它能够处理任何类型的数据,而不考虑它们的格式和存储方法。在实际应用中,这种多样性意味着可以访问驻留在 Excel 电子数据表、文本文件、电子邮件

Shall we treat BSTR type in COM as value or reference?

泄露秘密 提交于 2019-12-05 10:04:49
From book ATL Internals , I knew BSTR is different from OLECHAR*, and there are CComBSTR and CString for BSTR. According MSDN Allocating and Releasing Memory for a BSTR , I knew memory management responsibility for caller/callee. Take this line from MSDN, HRESULT CMyWebBrowser::put_StatusText(BSTR bstr) I still do not know how to handle bstr properly in my implementation. Since I still have a basic question for BSTR -- should we treat bstr as a value (like int) or as a reference (like int*), at least on COM interface boundary. I want to convert BSTR as soon as possible to CString/CComBSTR in

文件读写路径问题

瘦欲@ 提交于 2019-12-05 03:07:50
extern CWinApp theApp; char szAppName[MAX_PATH]; :: GetModuleFileName(theApp.m_hinstance, szAppName, MAX_PATH); CString strAppFullName; strAppFullName.Format(“%s”, szAppName); CString strTempPath = _T(“”); strTempPath = strAppFullName.Left(strAppFullName.ReverseFind(‘//’)+1)+_T(“Temp”); ------------------------------------------------------------------------------------ http://www.xuebuyuan.com/1791829.html 来源: https://www.cnblogs.com/music-liang/p/11901059.html