cstring

CStringT to char[]

I'm trying to make changes to some legacy code. I need to fill a char[] ext with a file extension gotten using filename.Right(3). Problem is that I don't know how to convert from a CStringT to a char[]. There has to be a really easy solution that I'm just not realizing... TIA. ...

C string comparison problem in c++

I've been having trouble with comparison in my c++ program. This is the boiled down version. #include "stdafx.h" #include <iostream> #include <windows.h> using namespace std; int main(int argc, char *argv[]) { if(argc>2){cout<<"3+Args"<<endl;}else//??? if(argc==2){ cout<<"2args"<<endl; if(argv[1]=="/hide-icons"){} if(argv[1]=="/...

simple string runtime error in C?

This code compiles fine but give segmentation fault error while running? Can anyone tell why? #include <stdio.h> #include <string.h> #include <math.h> int main() { const char s2[] = "asdfasdf"; char* s1; strcpy(s1, s2); printf("%s", s1); return 0; } ...

Writing into c-string

Hi, my code segfaults and I don't know why. 1 #include <stdio.h> 2 3 void overwrite(char str[], char x) { 4 int i; 5 for (i = 0; str[i] != '\0'; i++) 6 str[i] = x; 7 } 8 9 int main(void) { 10 char *s = "abcde"; 11 char x = 'X'; 12 overwrite(s, x); 13 printf("%s\n", s); 14 return 0; 15 } The gdb ...

C++ difference between automatic type conversion to std::string and char*

As a learning exercise, I have been looking at how automatic type conversion works in C++. I know that automatic type conversion should generally be avoided, but I'd like to increase my knowledge of C++ by understanding how it works anyway. I have created a StdStringConverter class that can be automatically converted to a std::string, ...

Cannot modify C string

Consider the following code. int main(void) { char * test = "abcdefghijklmnopqrstuvwxyz"; test[5] = 'x'; printf("%s\n", test); return EXIT_SUCCESS; } In my opinion, this should print abcdexghij. However, it just terminates without printing anything. int main(void) { char * test = "abcdefghijklmnopqrstuvwxyz"; ...

How is std::string implemented ?

I am curious to know how std::string is implemented and how does it differ from c string?If the standard does not specify any implementation then any implementation with explanation would be great with how it satisfies the string requirement given by standard? ...

How to get a CString object from a file with CFile::Read() in Unicode?

The charset is Unicode. I want to write a string of CString type into a file, and then read it out from the file afterwards. I write the string into a file with CFile::Write() method: int nLen = strSample.GetLength()*sizeof(TCHAR); file.Write(strSample.GetBuffer(), nLen); Here is the question: I want to obtain the CString from the fil...

Link error CString

I'm getting a linker error using CString the error is: error LNK2001: unresolved external symbol "private: static class ATL::CStringT<wchar_t,class StrTraitMFC<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > CConfiguration::_campaignFolderPath" (?_campaignFolderPath@CConfiguration@@0V?$CStringT@_WV?$StrTraitMFC@_WV?$ChTraitsCRT@_W@ATL@@@@@A...

Decrypting data files with wincrypt. Having trouble. Example shows CBase64Utils?

I need to decrypt some data files with wincrypt and examples are few and far between online. The most solid example I've found is here. However, this is using all sorts of types I cannot seem to find information about (CBase64Utils, CString, etc). I am reading the final solution, trying to understand the process, and have come to this...

CString extract file path

Hey I'm trying to extract the file path but the problem is that I'm stuck in an infinite loop don't understand why. Please have a look at my code. CString myString(_T("C:\\Documents and Settings\\admin\\Desktop\\Elite\\Elite\\IvrEngine\\dxxxB1C1.log")); int pos = myString.Find(_T("\\")); while (pos != -1) { pos = myString.Find(_T(...

Allocate room for null terminating character when copying strings in C?

Hello, so say I have this: const char* src = "hello"; Calling strlen(src); returns size 5... Now say I do this: char* dest = new char[strlen(src)]; strcpy(dest, src); That doesn't seem like it should work, but when I output everything it looks right. It seems like I'm not allocating space for the null terminator on the end... i...

What is the proper way to compare an element of an std::string with a character?

Hello, I am not a very experienced C++ programmer, i get a warning when i do the following: if (myString[i] != 'x') { } what is the appropriate way to compare these? thanks for your help! ...

Convert Wstring to CString

i have a variable of Cstring,need to convert it to wstring. ...

how to convert CString to Bytes

i am actually tryin to convert a csharp code to c... below is the C# code.. CString data = "world is beautiful"; Byte[] quote = ASCIIEncoding.UTF8.GetBytes(data); in the above code... it converts the string into bytes..similarily is ther a way that i can convert it using C.. Can any body tell what wud be the quivalent code in C? P...

Strip first and last character from C string

I have a C string that looks like "Nmy stringP", where N and P can be any character. How can I edit it into "my string" in C? ...

How to find the number of data added in CStringArray

Helo guys, I am working wid CStringArray and i want to know how to find the number of datas added in a CStringArray . in the below i have a defined the size of the array as 10 but i have added only three 3 data,So i want to know the number of data's added to the array.(here its 3).Is there any way we can do it in CStringArray to...

Comparing character arrays and string literals in C++ without cstring

In my programming class we currently have a project that requires us to take arguments into the program. I then need to be able to check one of the arguments to see which value was passed to the program so that I can choose the appropriate behavior for the program to follow. In a previous homework assignment I did this with the strcmp fu...

CString : What does (TCHAR*)(this + 1) mean?

In the CString header file (be it Microsoft's or Open Foundation Classes - http://www.koders.com/cpp/fid035C2F57DD64DBF54840B7C00EA7105DFDAA0EBD.aspx#L77 ), there is the following code snippet struct CStringData { long nRefs; int nDataLength; int nAllocLength; TCHAR* data() { return (TCHAR*)(&this[1]); }; ... }; ...

Are there any Regression Tests coded in C/C++ to test all the functionality of CString (ATL/MFC)?

I am trying to do a comparison of CString from ATL/MFC to a custom CString implementation and I want to make sure that all the functionality in the custom implementation matches that of the ATL/MFC implementation. The reason we have a custom CString implementation is so that we can use it on *nix and Windows platforms. The interface is ...