how do i use a 'string' like c#

  • Thread starter Thread starter Hareth
  • Start date Start date
H

Hareth

string word = "cool";
in c#

how do i do that in c++

i searched online and i was lost.....
 
Hareth said:
string word = "cool";
in c#

how do i do that in c++

I't s amuch more complex issue in C++ because there are many different kinds
of strings:

// C++ standard library
#include <string>
using namespace std;

string word = "cool";


// "ASCII-Z string
const char* word = "cool";


// MFC CString
CString word = "cool";

// .NET String (compile with /clr)
#import <System.Dll>
using namespace System;

String word = "cool";

.... etc.

What do you want to do with the string? Are you writing .NET code, or
native (unmanaged) code?

-cd
 

I believe you forgot a ^ managed pointer symbol :)

String ^word = "cool";

And not to forget, my favorate string datatype, because (personally) I only
work with C++ in a COM environment, the CComBSTR

so
CComBSTR word(L"cool");
or
CComBSTR word;
word = L"cool";

(since I modified the CComBSTR class, It has the same manipulation
capabilities as CString);

and there also is a Widestring variant (because Ascii is ooold);
PWSTR word = L"cool";
 
Egbert Nierop (MVP for IIS) said:
I believe you forgot a ^ managed pointer symbol :)

String ^word = "cool";

No. He spoke about native std::string, not about managed System::String
(mark the case difference).

Arnaud
MVP - VC
 
Arnaud Debaene said:
Egbert Nierop (MVP for IIS) said:
"Carl Daniel [VC++ MVP]"
Hareth wrote:
string word = "cool";

I believe you forgot a ^ managed pointer symbol :)

String ^word = "cool";

No. He spoke about native std::string, not about managed System::String
(mark the case difference).

Arnaud
MVP - VC

gee, you're right. That also exists... :)
 
Arnaud said:
Egbert Nierop (MVP for IIS) said:
"Carl Daniel [VC++ MVP]"
Hareth wrote:
string word = "cool";

I believe you forgot a ^ managed pointer symbol :)

String ^word = "cool";

No. He spoke about native std::string, not about managed
System::String (mark the case difference).

.... but I did miss the ^ on my managed String.

-cd
 
Back
Top