| Subway Just as Unhealthy as McDonald’s !? in Real World News |
|
|
| Something's wierd with my..system in Hardware Hangout |
|
|
| MOST: Mars Orbiting Space Telescope in Science Discussion & News |
|
|
| Xbox: A New Generation Revealed in Microsoft Console |
|
|
| Seagate Expansion 1TB External Hard Disk issue, please help me! in Hardware Hangout |
|
Posted 01 October 2012 - 21:13
Posted 01 October 2012 - 21:33
Posted 01 October 2012 - 21:35
Posted 01 October 2012 - 21:45
std::string mystring; char y = 'd'; mystring = "Test"; mystring += y; textBox->Text = mystring.c_str();
char mystring[50]; char y = 'd'; strcpy( mystring, "Test" ); strncat( mystring, &y, 1 ); textBox->Text = mystring;
Posted 02 October 2012 - 02:16
String^ mystring; char y = 'd'; mystring = "Test"; mystring += y; textBox->Text = mystring;This is C++/CLI. The caret "^" on a type name is not C++ syntax, it denotes a managed type, here System::String. If you want to learn C++, make sure you create an empty C++ project, not a "CLR" project. You won't be able to work directly with Winforms with C++; if working with Winforms is what you want, learn C# instead. I strongly doubt you want to learn C++/CLI, it is more complicated than you can imagine and it doesn't serve much purpose besides building bridges between the native and the managed world.
mystring += y->ToString();But really, run from C++/CLI while there is still time. File -> New -> Project -> Visual C++ -> General -> Empty Project. Now you're doing real, ISO C++. It's complicated enough by itself.
Posted 02 October 2012 - 02:28
wchar_t y = L'd';
char y = 'd'; String ^value = Convert::ToString(y);
Posted 02 October 2012 - 19:21
class SecurePassword
{
private String password;
private int length;
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
Random random = new Random();
public void generatePassword(bool useUpper, bool useNumber)
{
char ch;
int i;
int type;
password = "";
for (i = 0; i < this.length; i++)
{
type = (random.Next(0, 4));
if (type == 0 && useUpper)
ch = getRandomUpperChar();
else if (type == 1 && useNumber)
ch = getRandomDigit();
else
ch = getRandomLowerChar();
password += ch;
}
}
public char getRandomDigit()
{
byte[] byteCh = new byte[4];
double range;
uint intCh;
rng.GetBytes(byteCh);
intCh = BitConverter.ToUInt32(byteCh, 0);
range = intCh / 4294967296.0;
intCh = (uint)(range * 10);
return Convert.ToChar(intCh + 48);
}
public char getRandomLowerChar()
{
byte[] byteCh = new byte[4];
double range;
uint intCh;
rng.GetBytes(byteCh);
intCh = BitConverter.ToUInt32(byteCh, 0);
range = intCh / 4294967296.0;
intCh = (uint)(range * 26);
return Convert.ToChar(intCh + 97);
}
public char getRandomUpperChar()
{
byte[] byteCh = new byte[4];
double range;
uint intCh;
rng.GetBytes(byteCh);
intCh = BitConverter.ToUInt32(byteCh, 0);
range = intCh / 4294967296.0;
intCh = (uint)(range * 26);
return Convert.ToChar(intCh + 65);
}
public String getPassword()
{
return password;
}
public void setLength(int len)
{
length = len;
}
}
Posted 02 October 2012 - 22:46
Lord Method Man, on 02 October 2012 - 19:21, said:
private char getCharacter(uint start, uint range)
{
byte[] bytes = new byte[1];
// realistically, given the expected ranges (not even a full byte), you could use a single byte
rng.GetBytes(bytes);
return Convert.ToChar(start + bytes[0] % range);
}
ch = getCharacter((uint)'a', 26);
ch = getCharacter((uint)'A', 26);Any random number character:
ch = getCharacter((uint)'0', 10);