- #include <iostream>
-
#include <queue>
-
using namespace std;
-
void main()
-
{
-
int encode[8] = {3,1,1,1,3,1,1,1};
-
queue<char>myMagicWord;
-
myMagicWord.push('c');
-
myMagicWord.push('o');
-
myMagicWord.push('n');
-
myMagicWord.push('v');
-
myMagicWord.push('e');
-
myMagicWord.push('r');
-
myMagicWord.push('s');
-
myMagicWord.push('a');
-
myMagicWord.push('t');
-
myMagicWord.push('i');
-
myMagicWord.push('o');
-
myMagicWord.push('n');
-
for (int i=0; i<9; i++)
-
{
-
for (int j=0; j<encode[i]; j++)
-
myMagicWord.pop();
-
if(!myMagicWord.empty())
-
cout << myMagicWord.front();
-
//return(0);
-
}
-
-
-
}
4 1889
Please use CODE tags. That would have provided line numbers, making it easy to refer to your code.
The following snippet involves accessing array encode entries 0 through 8. Unfortunately, entry 8 doesn't exist. The array only has entries 0 through 7. - int encode[8] = {3,1,1,1,3,1,1,1};
-
...
-
for (int i=0; i<9; i++)
-
{
-
for (int j=0; j<encode[i]; j++)
-
...
@donbock
so wht will going to happen after the going through the loop and array cause is push and pop wht will be the result of that?
Accessing an array thorugh an out-of-bounds index is "undefined behavior". Anything can happen. Something different could happen each time. You cannot reliably predict what happens during "undefined behavior". You should try hard to expunge all undefined behavior from your programs.
Donthomasino,
Donbock was kind enough to explain that there is an error in the code...and was kind enough to explain the error in detail.
Why don't you compile the code and run it to find out what happens first hand?
I know of no better way to learn than through experience.
-Frinny
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Philip D Heady |
last post by:
Ok, as some of you may know I'm an Oracle newbie w/ PHP. I'd rather use
MySQL but at the office here we use Oracle and boy do I have alot to learn.
I'm starting to hate it after using MySQL!!
...
|
by: Bart Nessux |
last post by:
The below code works well, except for the database insert. I want each
element of the array to be inserted into the database, but only the last
element of the array is inserted... all the elements...
|
by: Phil Powell |
last post by:
if (is_array($_POST)) {
foreach ($this->getAssocSectionsObjArray($key, $dbAP) as
$obj) {
print_r($obj); print_r(" in array? ");
print_r(in_array($obj, $result)); print_r("<P>");
if...
|
by: Phil |
last post by:
Hi,
I don't understand this strange behaviour:
I compile this code :
#include <Python.h>
#include"Numeric/arrayobject.h"
static PyObject *
|
by: bidalah |
last post by:
Hi,
Following is a simple version of my now non-working code:
hihi = Dir("c:\burn2\*.*", FileAttribute.Normal)
Do While Len(hihi) > 0
hoho = hehe
hihi = Dir()
Loop
|
by: AMP |
last post by:
Hello
I get 2 errors in the following code that I cant Debug without some
help.
They are both in the TryParse function. Seems simple enough.The Errors
are Below.
private void...
|
by: ianenis.tiryaki |
last post by:
well i got this assignment which i dont even have a clue what i am
supposed to do. it is about reading me data from the file and load
them into a parallel array here is the question:
Step (1)
...
|
by: Peterwkc |
last post by:
Hello all expert, i have two program which make me desperate bu after i have noticed the forum, my future is become brightness back.
By the way, my problem is like this i the first program was...
|
by: ptq2238 |
last post by:
Hi, I'm getting confused with arrays and hope someone can shed light
on my code.
I wrote this to try and learn about files and arrays as I thought if I
could grab each element and place them into...
|
by: anuptosh |
last post by:
Hi,
I have been trying to run the below example to get a Oracle Array as an output from a Java code. This is an example I have found on the web. But, the expected result is that the code should...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |