cstring

Converting an int into a base 2 cstring/string

£可爱£侵袭症+ 提交于 2019-12-23 16:34:28
问题 In visual studio on my PC I can use itoa() to convert from a base ten int to a base 2 c-string. However when I am on a Linux machine that function isn't supported. Is there another quick way of doing this kind of conversion? I know how to use a string stream and I can use the dividing and modding to convert to another base manually. I was just hopping that there was an easier way of accessing the binary representation of an int. 回答1: You could use std::bitset<N> with a suitable N (e.g., std:

VC笔记

╄→尐↘猪︶ㄣ 提交于 2019-12-22 11:27:49
学生成绩管理系统详细设计说明书 1, 引言: 1.1 编写目的: 明细学生成绩管理系统软件的开发途径和应用方法 1.2 背景及范围 :    项目名称:学生成绩管理系统 项目任务:具体化、合理化地管理学生的学生成绩档案 1.3 参考资料: 《软件工程导论》 1.4 需求分析: 以学生成绩管理者的需求的出发点,设计方便成绩管理的系统,同时做到良好的交互性。 ① 增加,删除,修改学生基本信息与成绩 ② 动态添加与修改课程信息 ③ 用户可自定义多条件查询 ④ 实现不同分数段人数的统计图(柱状图,折线图,饼状图)显示 ⑤ 读取课程信息文件与学生信息文件 ⑥ 学生基本信息与成绩的保存与加载 ⑦ 计算学生加权平均分并生成学生成绩排名表 ⑧ 成绩表、课程信息表、排名表视图 2, 设计明细与测试 2.1 数据流 数据流图1-1: 数据流图1-2 2.2 设计明细: 2.2.1 工程说明 本程序基于SDI 并且视图类继承CFormView类。 SDI 结构下面板类对象,视图类对象,应用程序类对象的获得方法 CSJ4App *app=(CSJ4App*)AfxGetApp(); CMainFrame* pMain=(CMainFrame*)AfxGetMainWnd(); CSJ4View* vv =(CSJ4View*) pMain->GetActiveView();

Heap corruption when deleting a string

只愿长相守 提交于 2019-12-22 11:22:49
问题 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

Heap corruption when deleting a string

左心房为你撑大大i 提交于 2019-12-22 11:20: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

URL escaping MFC strings

一笑奈何 提交于 2019-12-22 07:57:13
问题 How do you URL escape an MFC CString? 回答1: InternetCanonicalizeUrl() 回答2: I created a wrapper function for others who may come across this solution. Also requires linking to Wininet.lib and including wininet.h bool EscapeURL ( CString& url, DWORD options = ICU_DECODE | ICU_ENCODE_PERCENT ) { DWORD bytes = url.GetLength () + 1; LPTSTR escapedString = new TCHAR[bytes + 1]; escapedString[0] = 0; // First read will generate the correct byte count for the return string // bool result =

CMutablePointer<CString> to String in swift-language

这一生的挚爱 提交于 2019-12-21 19:56:54
问题 I have a library which has a function like this: int get_user_name(const char **buffer); in swift, should call like this: var name:CMutablePointer<CString> = nil get_user_name(name) I want make use this function more comfortable so I wrapped this up: func get_username() -> String { var name:CMutablePointer<CString> = nil get_user_name(name) // how to convert name to String } I question is how to convert name to String 回答1: It goes something like: var stringValue :CString = "" name

How would you improve this algorithm? (c string reversal)

可紊 提交于 2019-12-21 12:31:31
问题 Working through some programming interview challenges I found online, I had to write an algorithm to reverse a const char * and return a pointer to a new char *. I think I have it, but to make it work properly I had to do some wonky stuff - basically having to account for the null-terminating character myself. Somehow I feel this is wrong, but I'm stumped, and I was wondering if someone could help me out: char * reverse(const char * str) { int length = strlen(str); char * reversed_string =

Conversion of UTF-8 char * to CString

孤街醉人 提交于 2019-12-21 05:28:06
问题 How do I convert a string in UTF-8 char* to CString? 回答1: bool Utf8ToCString( CString& cstr, const char* utf8Str ) { size_t utf8StrLen = strlen(utf8Str); if( utf8StrLen == 0 ) { cstr.Empty(); return true; } LPTSTR* ptr = cstr.GetBuffer(utf8StrLen+1); #ifdef UNICODE // CString is UNICODE string so we decode int newLen = MultiByteToWideChar( CP_UTF8, 0, utf8Str, utf8StrLen, ptr, utf8StrLen+1 ); if( !newLen ) { cstr.ReleaseBuffer(0); return false; } #else WCHAR* buf = (WCHAR*)malloc(utf8StrLen);

Breaking down string and storing it in array

和自甴很熟 提交于 2019-12-20 10:44:36
问题 I want to break down a sentence and store each string in an array. Here is my code: #include <stdio.h> #include <string.h> int main(void) { int i = 0; char* strArray[40]; char* writablestring= "The C Programming Language"; char *token = strtok(writablestring, " "); while(token != NULL) { strcpy(strArray[i], token); printf("[%s]\n", token); token = strtok(NULL, " "); i++; } return 0; } It keeps giving me segmentation error and I cannot figure it out. I believe it has something to do when I

MFC总结

孤街浪徒 提交于 2019-12-18 19:02:25
1.首先是ListControl 简介: 列表视图控件List Control同样比较常见,它能够把任何字符串内容以列表的方式显示出来,这种显示方式的特点是整洁、直观,在实际应用中能为用户带来方便。     列表视图控件是列表框控件List Box的改进和延伸。列表视图控件的列表项一般有图标(Icon)和标签(Label)两部分。图标是对列表项的图形描述,标签是文字描述。当然列表项可以只包含图标也可以只包含标签。     列表视图控件有4种风格:Icon、Small Icon、List和Report。下面简单说下4种风格各自的特点:     Icon大图标风格:列表项的图标通常为32×32像素,在图标的下面显示标签。     Small Icon小图标风格:列表项的图标通常为16×16像素,在图标的右面显示标签。       List列表风格:与小图标风格类似,图标和文字的对齐方式不同。     Report报表风格:列表视图控件可以包含一个列表头来描述各列的含义。每行显示一个列表项,通常可以包含多个列表子项。最左边的列表子项的标签左边可以添加一个图标,而它右边的所有子项则只能显示文字。这种风格的列表视图控件很适合做各种报表。    我的理解就是windows资源管理器,“查看”标签下的“大图标,小图标,列表,详细资料” 创建: