I am making a basic GUI password creator that creates a random sequence of letters, numbers, and symbols in C++ (it's a Windows Forms Application). I am using a numericUpDown object to retrieve the user input for the length of the password being created. I am trying to define a char array using that number as the length, but I get an error that says "expected constant expression." I tried defining it as a constant variable but even that doesn't work. Is there any workaround?
The below code is part of what is executed when the "Randomize" button is pressed (the button that prompts the password to be created and then displayed.
const int length = System::Convert::ToInt16(numericUpDown1->Value);
And then later in the program:
char p[length];
You cannot declare arrays with a variable size in c++ (same goes for c++/cli).
It sounds like you want to generate a random array of characters and convert it to a System::String (System::String is immutable, so you need the array to manipulate the data). For this, you'll want to use a array<wchar_t> instead.
array<wchar_t>^ data = gcnew array<wchar_t>(System::Convert::ToInt32(numericUpDown1->Value));
// fill each character in data with a random character.
System::String^ password = gcnew System::String(data);
Edit: in case you're wondering why a wchar_t instead of char: in c++/cli, wchar_t is analogous to System::Char, which is the character type used by .NET. char would be analogous to System::SByte (a signed byte).
Related
In the IAR Embedded Workbench I have a pointer pointing to a buffer in memory. When watching the pointer, I can see the contents of the word it points to. How can I tell the Watch view to list a range of the buffer, from the pointer onwards, for some specified length of elements?
For example, enter the expression:
myPtr[0..2]
will display information equivalent to the three expressions:
myPtr[0]
myPtr[1]
myPtr[2]
From the Iar Embedded Workbench (9.20) help:
In windows where you can edit the Expression field and in the Quick
Watch window, you can specify the number of elements to be displayed
in the field by adding a semicolon followed by an integer. For
example, to display only the three first elements of an array named
myArray, or three elements in sequence starting with the element
pointed to by a pointer, write:
myArray;3
To display three elements pointed to by myPtr, myPtr+1, and
myPtr+2, write:
myPtr;3
Optionally, add a comma and another integer that specifies which
element to start with. For example, to display elements 10–14, write:
myArray;5,10
To display myPtr+10, myPtr+11, myPtr+12, myPtr+13, and
myPtr+14, write:
myPtr;5,10
An alternative would be to view it in memory. Select View -> Memory and enter the pointer value (with 0x prefix). You can view and edit the range of data. Maybe not as "clean" as a traditional debugger variable viewer but it does the job.
Im creating a simple program that will compare user input to a predetermined string (for memorization help). So far, after the user pushes space a code will run to break the user input text into individual characters (in an array) to test it against the original.
When the user pushes space and one of the letters is wrong, I want that letter to turn a different color. Is there any way to store htmlText in an array, or can anyone think of a way to make that letter turn the color?
Is there any way to write the program at all? Am I able to keep the text in a string and compare it (the spaces and punctuation need to be ignored)?
You can change color without htmlText.
Use setTextFormat.
example:
var format:TextFormat = textField.getTextFormat(wrongLetterBeginIndex, wrongLetterEndIndex);
format.color = 0xFF0000;
textField.setTextFormat(format, wrongLetterBeginIndex, wrongLetterEndIndex);
For instance, to represent a QStringList int GUI listview we just create a QStringListModel and bound it to the GUI. example here.
In my case i have a file filled with integers, what i whant to do is parse the file into my memory for instance in integer array so i could work with data. Now, how do i bound this data to my gui, and if integer array is not apropriate, what kind of data structure should i choose?
int array[3] = {1,3,2};
model = new Q***Model(this);
model->set***(array);
To bound custom data to a view you need QStandardItemModel along QStandardItem, using that combination should also eliminate the need to use an array to store your file input.
QStandardModelItem
You Can Simply Convert the integers to string, Create a Qlist of Standard item model Using the Strings gotten from the integer . Assign to each Standard item its integer data; Than append the standard item to the qlist. Check http://doc.qt.digia.com/qt/qstandarditem.html#setdata
several ways to Convert to string http://www.qtforum.org/article/24878/convert-int-to-qstring.html
I have a 2d char array i.e. char myarray[5][5], I need to display the characters in a series of textboxes on the form application. There are two issues here:
The array is constructed by an external function, not a part of the public ref class form1 and i need to call the function of display which has to be defined inside form1 to access textboxes from the external function.
Even if i'm able to do that how do i display char in textboxes? It seems to accept only Sytem String^ type data.
I have reached the following conclusions (these might not be the ideal or good programming practices, but since no one has answered yet I'll tell how to get this through):-
Set a global variable. Store the processed data in it.
Access this data from Form1.
Convert data from string to System::String^ using gcnew
String^ myarray_str = gcnew String(myarray);
How do you save an array or an ArrayList in VB.NET using My.Settings? I cannot find the array type anywhere, even in the browse window.
I know I can convert the array to a string, but I do not know how to convert a string to an array. I know that if I were to break it at a delimiter then I could convert a string to an array, but my problem is that any text at all could be stored within the array as a single value, so I cannot pick a delimiter that is unlikely to be used.
I was also facing the same problem and I came up with a solution to this.
Here are the steps:
Open up the properties of your app and select settings
select the setting name and then where it says type click on the
arrow and select browse.
in the browse window type in system.collections.arraylist and hit enter!
there you have your array!
You can use array like this:
your_array_name(here_comes_the_item_no.) = whatever
What kind of array? I've had luck using StringCollection for strings. ArrayList works for most anything else (and that's about the only place I'd use arraylist).
I would either use the StringCollection type, and just convert your elements to/from strings when storing them in my.settings, or use XML Serialization to turn the array in to an xml string, and store that in my.settings.