C++ :: Unexpected Result Decrementing End Of Range Iterator In Call To Transform Algorithm

Aug 23, 2013

I found this piece code on the following site:

[URL]

I predicted the outcome as being 01230 as I thought the prefix decrement operator on iterator ce would prevent the final element of the list from being transformed.

I was wrong, the correct output is 01234.

So, I removed the decrement prefix and ran the test again, expecting a different result. It wasn't! The result was still 01234.

Only when I decremented ce twice did I get the result I initially expected, 01230.

why the first decrement of ce appears to have no effect?

#include <algorithm>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <cstdio>
int main() {
typedef std::list<int> L;

[code]....

View 2 Replies


ADVERTISEMENT

C++ :: Reverse Array - Unexpected Result

Jun 20, 2013

i use dev c++...i write this code to reverse an array and save the result in the same one

if n=3 i expect
a[0]=0 a[1]=1 a[2]=2 (before rev is OK but after calling rev)
a[0]=2 a[1]=1 a[2]=0 (expected result )
but i get
n=3

[code].....

View 4 Replies View Related

C++ :: Upon Checking Emptiness Of Array - Getting Unexpected Result

May 9, 2015

node = pool.at(0) is executed even though pool is empty,

I even tried pool.size() == 0, that line is still executed. What is the reason, I wonder?

Code:
NodePoolNode* NodePool::acquireNode(int x, int y, long t) {
std::stringstream key;
key << x << ":" << y << ":" << t;
NodePoolNode* node = usedNodes[key.str().c_str()];
if (node == NULL) {

[Code] ....

View 3 Replies View Related

C++ :: How To Check Result Returned From Iterator

Feb 7, 2012

Code:
it = m_CoopTable->m_SparseMap.find(s);
if (it != NULL) //Error
{
return false;
}

This gives me compile-time error. it is an iterator to a hash_map

View 9 Replies View Related

C++ :: Efficient Algorithm On List Iterator

Mar 6, 2013

I have a list and a vector, for example like

list<int> mylist = {1, 1, 1, 0, 0, 1, 0, 0}
vector<int> myvec;

I want to create an efficient algorithm to erase all element of value "1", and give these elements to a vector. My code (not efficient) is as follows

for(auto it = mylist.begin(); it != mylist.end(); it++) {
if(*it == 1) {
myvec.push_back(*it);
it = mylist.erase(it);
if(it != mylist.begin())
it--;
}
}

View 8 Replies View Related

C++ :: Transform XML To TXT

Apr 14, 2015

This is how my .xml page looks in a web browser. Is there a way to transform my .xml file into .txt file so that the text file would look like this?

View 14 Replies View Related

C# :: Transform Seconds Into HH:MM:SS?

Jun 18, 2014

I am trying to transform seconds into HH:MM:SS. I thought it would be easy using the TimeSpan functions however my hours exceed 24 hours now and then therefor it is not viable for use.

private string getFormattedTimeFromSecond(double second)
{
TimeSpan t = TimeSpan.FromSeconds( second );
string answer = string.Format("{0:D2}h:{1:D2}m:{2:D2}s",
t.Hours,
t.Minutes,
t.Seconds);
}

This is what I have tried, however it does not like it much when hours exceed 24.

View 6 Replies View Related

C++ :: Doing Fourier Transform - Different Frequencies

Jul 5, 2013

I am having problems doing the fourier transform:

[URL] .....

My code is:

esc = 2;
maxi = 0;
fu = 500;
fo = 3000;

for (f=fu;f<=fo;f + esc) {

[Code] ....

Don't worry about the exp and complex numbers because they work correctly. N is the number of samples of the input (2500). Esc is the difference between different frequences. So the samples of the output are (1250).

View 3 Replies View Related

C++ :: How To Transform A String Into A Char

Feb 8, 2015

I have had quite a head spinner on trying to transform a string into a char. I've been trying to do this for the project below.

[URL] ....

std::string str = "string";
const char* chr = str.c_str();
cout << *chr << endl;

Above is the code I have tried using and it stores data under *chr, it however only stores one letter rather than the entire word like for example string.

View 2 Replies View Related

C++ :: Transform TXT File To Char Vector?

Aug 17, 2013

I need to transform a .txt file to a char vector, but how to do it. as much as I could until now been transformed into vector string.

Code:
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;

[Code].....

View 7 Replies View Related

C++ :: Transform Integer Array To BMP Image

Jun 8, 2013

I have a problem concerning transforming int array into bmp image. I wanted to add a post in this topic: [URL] .... , but unfortunately it is closed. Actually I have a question concerning the code written by Duoas. I have a function which takes values from the file and I want to convert it into bmp with the use of Duoas code. I do it like that(it's Duoas code + my load and main function) Is it something wrong with how I do it or it's rather sth wrong with the file.

It compiles without errors but when I run it: core dumped.

According to gdb debugger problem is here: double hue = (intarray[ row - 1 ][ col ] - min_value) * granularity; programs stops, segmentation fault ...

#ifndef INTARRAY2BMP_HPP
#define INTARRAY2BMP_HPP
#include <fstream>
#include <iostream>
#include <string>

[Code] ....

View 2 Replies View Related

C++ :: Unexpected Output In Example Function

Jan 21, 2015

I am currently trying to understand why this example for using an array as an argument in a function has a different result than what the lecture notes say it should be.

So supposedly sum should return with the value 28, but I get 27 no matter what. I also am not very good at reading and understanding what exactly the order of operations for this function are.

Code:
#include <iostream>
using namespace std;

int sum(const int array[], const int length) {
long sum = 0;
for (int i = 0; i < length; sum += array[++i]);
return sum;

[Code] ....

View 3 Replies View Related

C :: Unexpected Output With Char

Sep 14, 2013

I tried running the code below and i got an unexpected output

Code:

#include<stdio.h>
void main() {
char a='A';
while(a)

[Code] ....

The code is supossed to give an infinite loop but instead it terminates with a=0...I tried running it with some casting like this

Code:

#include<stdio.h>
void main(){
char a='A';
while((int)a)

[Code] ....

But the output was the same as before.why the code has this unexpected behaviour???

View 7 Replies View Related

C++ :: Unexpected SIGABRT At Return 0

Jun 24, 2013

I am working through Binary IO with objects and am running into a curious error.

The program executes perfectly until it hits the very end. At "return 0", the program fails. The debugger picks up SIGABRT when executing "return 0". This seems to me to indicate a deconstructor problem of some kind. However, I can't seem to find any deconstructor problems (I am fairly new at programming though).

If I comment out the following two lines:

"binaryio.read(reinterpret_cast<char *>(&studentNew1), sizeof(Student));"
"binaryio.read(reinterpret_cast<char *>(&studentNew2), sizeof(Student));"

then the program finishes exiting without error . . . . but the whole point is to be able to read from the binary file. With those two lines in the code, the program successfully reads from the file and outputs the objects to the console ,but fails at "return 0";

Here is the code:

#include <iostream>
#include <fstream>
#include "Student.h"
using namespace std;

void displayStudent(Student student) {
cout << student.getFirstName() << " ";

[Code] .....

View 5 Replies View Related

C++ :: Unexpected Output From Fprintf?

Feb 11, 2014

I have the following piece of code which should write the contents of my vetor to y file but I am getting a very weird output in my file.

for (int i=0;i<amount;i++) {
fprintf(pFileO,"Case #%d: ",i+1);
for (int j=0;j<words[i].size();j++) {

[Code].....

As you can see this doesn't make sene because the file should also contain the exact same things as the cmd outputs. What's going on here ?

View 1 Replies View Related

C :: Verified Code For Computing Fast Furrier Transform Of Image

Jun 9, 2013

i am looking for a verified code in simple c, for generating fft of an input image (.jpg). the output can be a text file including fft coefficients.can you recommend me any source except open-cv?

View 6 Replies View Related

C++ :: Photoshop - Change Color Of Anchor Point In Transform Tool?

Aug 4, 2014

I was wondering if its possible to change the color of the anchor point in the transform tool.

Is this possible? Sometimes I'll move it and it takes forever to find it again on a dark image. The actual image of the cross hairs must live in the application contents somewhere? Or its made by script. After a quick search of "transform" I found this file.. Not exactly sure what I'm looking at inside but it appears to be c++ code? [URL] ....

SCREEN GRAB: [URL] ....
FILE: [URL] ....

View 1 Replies View Related

C++ :: Getting Unexpected Outputs For Bitfields And Floats

Aug 7, 2013

I'm getting unexpected output in 2 different cases. The 1st deals with bitfields. The C++ standard has this line about integral promotions:

An rvalue for an integral bit-field (9.6) can be converted to an rvalue of type int if int can represent all the values of the
bit-field; otherwise, it can be converted to unsigned int if unsigned int can represent all the values of the bit-field.

If the bit-field is larger yet, no integral promotion applies to it. If the bit-field has an enumerated type, it is treated as any other value of that type for promotion purposes.

This sounds like the value of a bitfield will always be treated as a signed int if the signed representation of the value will fit in the bits. This seems to hold true for my C compiler, but not my C++ compiler.

I tried storing a small negative value in a bitfield that has enough bits to store the sign bit and the value. But when I print out the bitfield, I always get a large number

In the example code below, I expect the output:

Code:
foo.x = -1
foo.y = -2
foo2.x = 31
foo2.y = 6
foo3.x = -1
foo4.x = 4294967295 But I get: Code: foo.x = 31
foo.y = 6
foo2.x = 31
foo2.y = 6
foo3.x = -1
foo4.x = -1 -------------------

The other issue I'm having is sort of similar. I'm trying to store 4294967295 into a float, but when I print it out, I get 4294967296. i've tried storing a few other large values like this and what's printed out is rarely the value I stored. I thought it might be because of some int to float conversion, so I tried 4294967295.0. Still no luck. Then I remember that defaults to a double so maybe that's the issue so I tried 4294967295.0f. Still no luck. Why can't I store the correct value here? I don't think it's an IEE format thing since I can use these values as floats on a calculator program.

The example code showing both issues is below.

Code:
#include <stdio.h>
typedef struct {
signed char x : 5;
signed char y : 3;
}my_struct_t;

[Code] .....

View 11 Replies View Related

C++ :: Unexpected Expression Compiler Error

Jul 30, 2013

My compiler (GCC) keeps expecting an expression where it shouldn't in 1 specific piece of my code:

int zxcNewWindow( HWND parent, TCHAR *text, zxWINDOW *kid,
UINT style, int x, int y, int w, int h, int type )
// right here
{
*kid = zxDefWINDOW;

The project contains only 2 files right now and the settings are just the default for an empty Code::Blocks 12.11 project. Both files are in UTF-8 format (tried in ASCII too), I just cannot see why this is not compiling correctly. I'll post the files in the next two posts.

Edit: For those of you who didn't get what the error was from the above here's the full log:

mingw32-gcc.exe -Wall -g -DzxDEBUG -c C:MePrjscppzxGUImain.c -o objmain.o
C:MePrjscppzxGUImain.c: In function 'zxcNewWindow':
C:MePrjscppzxGUImain.c:39:10: error: expected expression before '{' token
Process terminated with status 1 (0 minutes, 0 seconds)
1 errors, 0 warnings (0 minutes, 0 seconds)

View 8 Replies View Related

C++ :: Analysis Of Discrete Wavelet Transform - Modifying For Loop To Make It Faster

Aug 25, 2014

I have this code which performs the analysis part of discrete wavelet transform. It works pretty well. However, I wish to reduce the time that it consumes even further. I did use reserve() and it worked upto few msec.

int rows = signal.size();
int cols = signal[0].size();
int cols_lp1 =(int) ceil( (double) cols / 2);
vector<vector<double> > lp_dn1(rows, vector<double>(cols_lp1));
vector<double> temp_row;
temp_row.reserve(512);

[Code] ....

View 5 Replies View Related

C++ :: Preventing The User From Feeding (Cin) Unexpected Values

May 2, 2013

I'm just starting c++, doing tutorials. So many tutorials. I've noticed that the tutorials all assume the same thing: That the user will always do exactly as he/she is told when asked for input.

Example: "Please enter your age:"

Now, the example code might be expecting the user to type some numbers, but what if the user feels like typing out the letters of their age?

"I am ninety five thank you very much, sonny"

I could specify to the user that I only want the information in number form, but what if the user is just being a dick?

What if the user types, "none o' yer business."?

So... how to approach "fool-proofing" player input?

View 2 Replies View Related

C++ :: Regex Unexpected Matching (Floating Point)

Oct 28, 2014

I have written this regex to match a floating point literal:

(^[[:space:]]*)(([0-9]+.?[0-9]*([eE][+-]?[0-9]+)?)|"
"(.[0-9]+([eE][+-]?[0-9]+)?))([fFdD]?[[:space:]]*)$

and when I match it with string like "123e" or "e2" it works while it shouldn't and I can't find the reason why.

View 2 Replies View Related

C++ :: Unexpected SIGSEG Abort When Working With Vector

Oct 9, 2013

I keep getting a segmentation error when ever I have the following code...

int main(void) {
//Section 1
unsigned long val = 12;
std::vector<unsigned long> vval;
for(unsigned long i = 0; i < 100; ++i) {
vval.push_back((unsigned long)0);

[Code] ....

Error: *** Error in `/home/alex/projects/bignum/build/bignum': free(): invalid pointer: 0x00007ffff75b5b88 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x80a46)[0x7ffff7274a46]

compiler is clang++ 3.2

It doesn't happen if I restructure it so that bignum::num is not a pointer to an std::vector<unsigned long>

View 10 Replies View Related

C/C++ :: Unexpected Behavior For Classes That Contain Member Object

Apr 1, 2014

I have a WordRecord that contains a LinkedList (both my doing). I have rigorously tested my LinkedList class, and know that it works (heck, I used it in the last project I had!). The problem is that undefined behaviour seems to happen when using the WordRecord, which has a std::string and a LinkedList<unsigned>. (The problem happens with the LinkedList.)

Here is the code:

main.cpp
#include <iostream>
#include "BinaryTreeNode.h" // here for test purposes
#include "LexicographicTree.h"
#include "LinkedList.h"//also for test purposes
#include "OutputStream.h"
#include "WordRecord.h"
using namespace std;
int main()
{
// setup the OutputStream to print to "test.txt"
OutputStream stream("test.txt");
// create a sampleWordRecord (make it have the word "I" on line 1)

[code]....

One of the requirements for the project is that it must compile on Unix server (I am using Windows, and have tested it in both environments.) I get a core-dump in the Unix environment. On the other hand, the output on-screen in the Windows environment looks right. However, when I open up the text file, I get the following

Sample word record:

WordLines
I{14}
/* I have no what is happening to sampleWordRecord's LinkedList; I am not trying to modify it, except for where I created the sampleWordRecord! */

View 14 Replies View Related

C++ :: Function To Build Multiplication Table Of Arbitrary Dimensions - Unexpected Output

Nov 8, 2013

So the latest challenge from jumping into c++ is as following.

Code:
Write a function that builds the multiplication table of arbitrary dimensions This chapter also talks a ton about 2d arrays.

So I've built my program thus far as this.

Code:
#include <iostream>
using namespace std;
int drawTable(int,int);
int main()

[Code] .....

So basically, the idea is that I can use the arrays dimensions as a placeholder, and just multiple them to get that specific spot, so table[0][0] = 0, [0][1] = 0 and so on. However the output actually seems to be randomly generated numbers so I'd like to ask, what am I doing wrong? Am I on the right track? Or have I missed the bus stop completely.

View 12 Replies View Related

C/C++ :: Sequential Matrix Multiplication Program - Syntax Error Near Unexpected Token

Apr 30, 2014

I wrote a sequential matrix multiplication program in c.

After execution i get error like
./mul.c: line 11: syntax error near unexpected token `('
./mul.c: line 11: `int main(){'

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define wA (30 * 16)
#define wB (50 * 16)
#define hA (80 * 16)
#define hB wA
#define wC wB

[Code] ....

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved