I implemented a C++ program and successfully compiled and ran on my laptop. However when I copy my code to another machine (school's sun machine), it didn't run properly. I can compile and run, but cout does not print everything. I used cout in a loop where it iterates no more than 20 times and it only prints the first iteration.
I used cout.flush() after each cout line, it also didn't work.
it iterates no more than 20 times and it only prints the first iteration.
How do you know how many times it iterates?
I would run the code in a debugger to see how many items are in the container dist
(or you could add code to print the number).
Wow, you're definitely right. The list has 1 element. Now my problem is changed, below is the code of the whole function:
Code:
//actorList is a vector which holds pointers of actor classes
//in an actor class there is an integer (dist) which represents the distance of
// current actor to another one. this function is supposed to generate new
// distances in map and if distance already exists in the map, dist map
// increases the value part of key. for instance, all actors whose distance
//is 5 count on map dist[5][n], n shows the total number of actors. if there
// is no key=5 in the map, it simply creates one and adds it to the map (using make_pair(_,_)).
void printDist(){
typedef map<int, int> mapType;
mapType dist;
dist.insert (make_pair(0 ,0));
mapType::iterator iter = dist.begin();
cout << "Size of actor list: " << (*actorList).size() << endl;
timer1.restart();
for(int i=0;i<(*actorList).size();i++){
iter = dist.find((*actorList)[i]->dist);
if(iter == dist.end()){
if(iter->first == (*actorList)[i]->dist){
dist.insert (make_pair((*actorList)[i]->dist ,1)); //add new distance to map
cout << "Element was inserted. Size of dist:" << dist.size() << endl;
}
}else{
iter->second += 1; //if distance already exists in map, simply increase the value by 1.
}
}
timer1.stop();
timer1.check("Actor list travel: ");
for(iter = dist.begin(); iter != dist.end(); ++iter)
cout << "Distance: " << iter->first << " , Value: " << iter->second << " Out of: " << dist.size() << endl;
}
It is weird, I can't understand why it works on Ubuntu but not on Solaris....
Hello,
I'm trying to print the value of my cursor in the dbms_output.put_line in shell script, but it only shows "PL/SQL procedure successfully completed." nothing else. I have set serveroutput on,
Below is my script : Any advise would be really helpful.
sqlplus -s $ORACLE_LOGON <<EOF >>... (2 Replies)
I'm trying to print out integers and space/newline for a nicer output, for example, every 20 integers in a row with ternary operator.
In C I could do it with:printf("%d%s",tmp_int, ((j+1)%20) ? "\t":"\n"); but could not figure out the equivalent in C++:
cout << ((j+1)%20)?... (4 Replies)
Heyas
Me trying some C.. cout in specific, thats what i remembered:
#include <stdio.h>
// -- Just the above or with all the below ones, no change
#include <stdio_ext.h>
#include <stdlib.h>
#include <wchar.h>
//#include <iostream> // I assume its the same anyway?
//#include <iostream.h>... (2 Replies)
Hi Gurus,
I have below sample script. I expect it print error when running script without input parameter. but the it doesn't.
would you please help me about this issue.
thanks in advance.
/script$cat test.ksh
#!/bin/ksh
while getopts :f: arg
do
case $arg in
... (4 Replies)
I am not sure where to post this other than here.
I am trying to figure out why an app gives different output when compiled under Ubuntu 10.10 and CentOS 5.5. I am pretty sure that the issue is that the Cent version has gcc 4.1 installed, while Ubuntu has gcc 4.4. I am trying to print from some... (20 Replies)
Hello,
Compilation of the line "cout = outFile" throws error
"Error: std::ios_base::operator=(const std::ios_base&) is not accessible from std::ios ::operator=(const std::ios &)."
outFile is declared as "static ofstream".
Thanks,
Shafi (3 Replies)
Hi I am running Ubuntu 9.10 and I use QtCreator for my C++ Programms.
I knwo that in wondows OS cout is located in iostream.h library.
It seems that it isn;t the same library in Qtcrator... :(
Anyway, iostream.h doesn't exist and iostream (without the .h) exists but doesn't seem to include the... (4 Replies)