cstring

How to pass a cstring from Delphi

I'm writing a tcp client in Delphi for a server that has a series of messages defined as c structs. Below is an example conversion of one of the messages: struct { int32 Reserved; cstring Name; int32 flags; } msg1 = record Reserved : integer; Name : cstring???; flags : integer; end Googling the type tell...

is there a way to use cin.getline() without having to define a char array size before hand?

Basically my task is having to sort a bunch of strings of variable length ignoring case. I understand there is a function strcasecmp() that compares cstrings, but doesn't work on strings. Right now I'm using getline() for strings so I can just read in the strings one line at a time. I add these to a vector of strings, then convert to cst...

Help with \0 terminated strings in C#

I'm using a low level native API where I send an unsafe byte buffer pointer to get a c-string value. So it gives me // using byte[255] c_str string s = new string(Encoding.ASCII.GetChars(c_str)); // now s == "heresastring\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0(etc)"; So obviously I'm not doing it right, how I get rid of the excess? ...

How do I get the next token in a Cstring if I want to use it as an int? (c++)

My objective is to take directions from a user and eventually a text file to move a robot. The catch is that I must use Cstrings(such as char word[];) rather than the std::string and tokenize them for use. the code looks like this: void Navigator::manualDrive() { char uinput[1]; char delim[] = " "; char *token; cout ...

Returning c_str from a function

This is from a small library that I found online: const char* GetHandStateBrief(const PostFlopState* state) { static std::ostringstream out; ... rest of the function ... return out.str().c_str() Now in my code I am doing this: const char *d = GetHandStateBrief(&post); std::cout<< d << std::endl; Now, at first d contained ga...

Works for Short Input, Fails for Long Input. How to Solve?

I've this program which finds substring in a string. It works for small inputs. But fails for long inputs. Here's the program: //Find Substring in given String #include <stdio.h> #include <string.h> main() { //Variable Initialization int i=0,j=0,k=0; char sentence[50],temp[50],search[50]; //Gets Strings printf("Enter Sentence...

How (if needed) to free dynamic memory when marshaling CString from C++ to C#?

I have CString cs on C++ side and IntPtr ip on C# side which contains value of cs through marshaling mechanism. Then, I simply get needed String as Marshal.PtrToStringAnsi(ip) and everything works fine, but I am wondering should I and if should, how can I delete unmanaged memory occupied by ip, i.e. cs? ...

How to marshal the type of "Cstring" in .NET Compact Framework(C#)?

How to marshal the type of "Cstring" in .NET Compact Framework(C#)? DLLname:Test_Cstring.dll(OS is WinCE 5.0),source code: extern "C" __declspec(dllexport) int GetStringLen(CString str) { return str.GetLength(); } I marshal that in .NET Compact Framework(C#),for example: [DllImport("Test_Cstring.dll", EntryPoint = "GetStringLen...

Having issues with initializing character array

Ok, this is for homework about hashtables, but this is the simple stuff I thought I was able to do from earlier classes, and I'm tearing my hair out. The professor is not being responsive enough, so I thought I'd try here. We have a hashtable of stock objects.The stock objects are created like so: stock("IBM", "International Business M...

unformatted input to a std::string instead of c-string from binary file.

ok i have this program working using c-strings. I am wondering if it is possible to read in blocks of unformatted text to a std::string? I toyed arround with if >> but this reads in line by line. I've been breaking my code and banging my head against the wall trying to use std::string, so I thought it was time to enlist the experts. ...

How can I tell if CString allocates memory on the heap or stack?

How can I tell if the MFC CString allocates memory on the heap or stack? I am compiling for the Windows Mobile/Windows CE platform. I am working on a project developed by someone else and I have witnessed stack overflows under certain circumstances. I am trying to figure out if the custom SQLite recordset classes (with many CString ...

Simple modification of C strings using pointers

I have two pointers to the same C string. If I increment the second pointer by one, and assign the value of the second pointer to that of the first, I expect the first character of the first string to be changed. For example: #include "stdio.h" int main() { char* original_str = "ABC"; // Get pointer to "ABC" char* off_by_o...

how to omit extra bits in a file?

I want to omit extra bit in txt file.eg ....ÿ 0111111110111101100011011010010001 in this string we want to omit extra bit ÿ which is appeared when we save a binary string. Save fun is as follow. please help me. void LFSR_ECDlg::Onsave() { this->UpdateData(); CFile bitstream; char strFilter[] = { "Stream Records (*.mpl)|...

How to write INT64 to CString

I am coding in c++ windows. INT64 dirID = -1; CString querySQLStr = _T(""); querySQLStr.Format(L"select * from ImageInfo where FolderPath=%64d;", dirID); querySQLStr always like this: select * from ImageInfo where FolderPath= 1214; is it right to use %64d? Many Thanks ...

Const char conversion error.

Hi, I am getting the following error with gcc. invalid conversion from ‘char**’ to ‘const char**’ With this code. void foo( const int &argc, const char **argv ); int main( int argc, char *argv[] ) { foo( argc, argv ); } Why is this? ...

Passing CString to IIS ServerSupportFunction function in ISAPI extension

I've been given an ISAPI extension dll compiled in VC6 which calls "ServerSupportFunction" through MFC's CHttpServerContext class. The code looks something like (assume Ctx is object of the class CHttpServerContext) CString str; str = "Content-Type: text/plain\r\n"; str += "Content-Length: 200\r\n"; str += "\r\n"; DWORD len = str.GetL...

Errors using typedef on CString when trying to get old code working

I've got some example code for controlling a wifi module that tells me to use VC 6.0, and that newer versions aren't supported. I'm trying to get it work, anyway. It uses CString, which is part of MFC, so I've downloaded a trial of Visual Studio 2010 to see if I can get it to compile. Here's the code that's throwing the (start of the) er...

#include being ignored

So, I've got this code I'm trying to update. It was written for visual studio 6, and I'm trying to get it to compile in visual studio 2010. In stdafx.h, it includes afx.h and afxwin.h and a few other things necessary for the program to work. Notably, there's usage of CString in other header files. At the top of the includes in stdafx...

How to concatenate multiple CString

All functions return CString, this is a MFC code and must compile in 32 & 64 bits. Currently I'm using CString sURI = GetURL(); sURI += GetMethod(); sURI += "?"; sURI += GetParameters(); Exists any manner to do the same like: CString sURI = GetURL() + GetMethod() + "?" + GetParameters(); ...

What is the most efficient way to convert STL string array to const char* array?

We have: std::string string_array[2]; string_array[0] = "some data"; string_array[1] = "some more data"; char* cstring_array[2]; What is the most efficient way to copy data from string_array to cstring_array? Or pass string_array to the function, needed "const char* cstring_array[]"? ...