cstring

VS2017出现不存在从\"CString\"到\"const char*\"的适当转换函数

点点圈 提交于 2019-12-05 02:29:36
出现不存在从CStrign到const char*的转换,可以将项目属性的字符集设置从"使用Unicode字符集“转换为”使用多字字符集“。 点击”项目“----“属性”----“配置属性”----”常规“----”字符集“更改即可! 来源: https://www.cnblogs.com/ming-4/p/11897888.html

MFC: std::string vs CString?

做~自己de王妃 提交于 2019-12-04 22:31:31
Using C++ with MFC. Coming from a C# background I typically just use string for all, well, strings. I use them for class members, method parameters, and method return values. Now in C++ I've got std::string, CString, char *, LPCTSTR, and more. As I design my data members, method parameters, and method return values which type(s) should I be using? Ease of use is important and CString seems to offer that but my instinct is toward portable standards although portability is pretty low on my list of priorities (now). Also, I don't like the c semantics of creating string buffers and passing them

Unicode下CString(wchar_t)转换为 char*

一笑奈何 提交于 2019-12-04 16:44:33
wstring MultCHarToWideChar(string str) { //获取缓冲区的大小,并申请空间,缓冲区大小是按字符计算的 int len=MultiByteToWideChar(CP_ACP,0,str.c_str(),str.size(),NULL,0); TCHAR *buffer=new TCHAR[len+1]; //多字节编码转换成宽字节编码 MultiByteToWideChar(CP_ACP,0,str.c_str(),str.size(),buffer,len); buffer[len]='/0';//添加字符串结尾 //删除缓冲区并返回值 wstring return_value; return_value.append(buffer); delete []buffer; return return_value; } string WideCharToMultiChar(wstring str) { string return_value; //获取缓冲区的大小,并申请空间,缓冲区大小是按字节计算的 int len=WideCharToMultiByte(CP_ACP,0,str.c_str(),str.size(),NULL,0,NULL,NULL); char *buffer=new char[len+1];

模板

我是研究僧i 提交于 2019-12-04 08:21:29
高斯消元 JSOI2008]球形空间产生器 #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> #include <vector> #include <stack> #include <queue> using namespace std; int n; double a[23][23], b[23], c[23][23], temp; int main() { scanf("%d", &n); for(int i = 1; i <= n + 1; i++) for(int j = 1; j <= n; j++) scanf("%lf", &a[i][j]); for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) { c[i][j] = 2 * (a[i][j] - a[i + 1][j]); b[i] += a[i][j] * a[i][j] - a[i + 1][j] * a[i + 1][j]; } for(int i = 1; i <= n; i++) { for(int j = i; j <= n; j++) { if(fabs(c[j][i]) > 1e-8) { for(int k = 1; k <= n; k++

删除目录(非空)、复制目录(非空)

谁说我不能喝 提交于 2019-12-04 06:27:39
本来想自己写的,看到一份博客已经总结的很完整了。直接引用下: 转载请注明原文链接。 原文链接: http://www.cnblogs.com/xianyunhe/archive/2011/12/06/2278550.html 文件和文件夹的创建、复制、删除、重命名等操作是经常要用到的,作者根据自己的经验,并查询了MSDN,特意总结了常用文件和文件夹的相关操作,重点讨论了复制整个文件夹和删除整个文件夹 1、文件操作基本函数 WinBase.h中声明了 Windows 平台下的基本的 API 函数,包括文件和目录的基本操作。 下面列出部分常用的文件操作相关函数。 函数 说明 DeleteFile 删除单个文件,不能删除目录和只读文件 CopyFile 复制单个文件 MoveFile 移动移动文件或目录 CreateDirectory 创建目录 RemoveDirectory 删除空目录 更多的函数可查询 Winbase.h 文件或者 MSDN 中的 File Management Functions 和 Directory Management Functions 。 2 、复制目录和删除目录 WinBase.h 中的文件操作函数中并没有直接实现整个文件夹的复制和删除操作的函数,需要自己实现。 (1)判断指定路径是否有效目录 1 /*判断一个路径是否是已存在的目录*/ 2 BOOL

How to elegantly initialize vector<char *> with string literal?

旧街凉风 提交于 2019-12-04 03:19:38
The problem comes from an exercise on C++ Primer 5th Edition: Write a program to assign the elements from a list of char* pointers to C-style character strings to a vector of strings. ----------------Oringinal Question------------ First I try the following somewhat direct way: vector<char *> vec = {"Hello", "World"}; vec[0][0] = 'h'; But compiling the code I get a warning: temp.cpp:11:43: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings] vector<char *> vec = {"Hello", "World"}; ^ And running the ./a.out I get a Segmentation fault (core dumped) I think it is

Converting String to Cstring in c++

吃可爱长大的小学妹 提交于 2019-12-03 19:05:24
问题 I am string to convert this string="apple" , and want to put that into c-string of this style, char *c , that holds {a,p,p,l,e,'\0'} . Which Predefined method should I be using? Thank you ahead. 回答1: .c_str() returns a const char* . If you need a mutable version, you will need to produce a copy yourself. 回答2: vector<char> toVector( const std::string& s ) { string s = "apple"; vector<char> v(s.size()+1); memcpy( &v.front(), s.c_str(), s.size() + 1 ); return v; } vector<char> v = toVector(std:

C++: how to convert ASCII or ANSI to UTF8 and stores in std::string

风流意气都作罢 提交于 2019-12-03 13:59:10
问题 My company use some code like this: std::string(CT2CA(some_CString)).c_str() which I believe it converts a Unicode string (whose type is CString)into ANSI encoding, and this string is for a email's subject. However, header of the email (which includes the subject) indicates that the mail client should decode it as a unicode (this is how the original code does). Thus, some German chars like "ä ö ü" will not be properly displayed as the title. Is there anyway that I can put this header back to

CString, BSTR, LPCTSTR 概念

纵饮孤独 提交于 2019-12-03 13:21:59
CString是一个动态TCHAR数组 , BSTR是一种专有格式的字符串(需要用系统提供的函数来操纵 ) LPCTSTR只是一个常量的TCHAR指针。 CString 是一个完全独立的类,动态的TCHAR数组,封装了+等操作符和字符串操作方法。 typedef OLECHAR FAR* BSTR; typedef const char * LPCTSTR; vc++中各种字符串的表示法 首先char* 是指向ANSI字符数组的指针,其中每个字符占据8位(有效数据是除掉最高位的其他7位),这里保持了与传统的C,C++的兼容。 LP的含义是长指针(long pointer)。LPSTR是一个指向以‘\0’结尾的ANSI字符数组的指针,与char*可以互换使用,在win32中较多地使用LPSTR。而LPCSTR中增加的‘C’的含义是“CONSTANT”(常量),表明这种数据类型的实例不能被使用它的API函数改变,除此之外,它与LPSTR是等同的。 1. LP表示长指针,在win16下有长指针(LP)和短指针(P)的区别,而在win32下是没有区别的,都是32位.所以这里的LP和P是等价的. 2. C表示const 3. T是TCHAR,在采用Unicode方式编译时是wchar_t,在普通时编译成char. 为了满足程序代码国际化的需要,业界推出了Unicode标准

How to remove first character from C-string?

老子叫甜甜 提交于 2019-12-03 09:27:17
问题 Can anyone please help me? I need to remove the first character from a char * in C. For example, char * contents contains a '\n' character as the first character in the array. I need to detect and eliminate this character, modifying the original variable after its been "sanitized". Can anyone help me with the code? I'm completely new to C, and just can't seem to figure it out. 回答1: if (contents[0] == '\n') memmove(contents, contents+1, strlen(contents)); Or, if the pointer can be modified: if