![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| cout 1.0.1 (Default branch) | iBot | Software Releases - RSS News | 0 | 06-11-2008 09:10 AM |
| Print to ps2pdf print queue | Sean_69 | SUN Solaris | 2 | 10-22-2007 08:00 AM |
| Print to a ps2pdf print queue. | Sean_69 | UNIX for Dummies Questions & Answers | 1 | 10-22-2007 07:58 AM |
| Print Problem in UNIX. Need to know the option to specify the print paper size | ukarthik | HP-UX | 1 | 06-07-2007 06:35 AM |
| How do I get awk to print a " in it's print part? | LordJezo | Shell Programming and Scripting | 2 | 06-27-2006 06:16 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
cout doesn't print everything
Hi all,
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. Below is the code snippet: Code:
for(iter = dist.begin(); iter != dist.end(); ++iter)//{
cout << "Distance: " << iter->first << " , Value: " << iter->second << endl;
cout.flush();
}
Thanks OS: Solaris Compiler: g++ |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
What is the purpose of the "//" before the "{" on the first line of your code?
|
|
#3
|
|||
|
|||
|
Below is my real code
Code:
for(iter = dist.begin(); iter != dist.end(); ++iter)//{
cout << "Distance: " << iter->first << " , Value: " << iter->second << endl;
//cout.flush();
//}
|
|
#4
|
|||
|
|||
|
Quote:
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). |
|
#5
|
|||
|
|||
|
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;
}
thanks. Last edited by SaTYR; 08-12-2008 at 01:59 PM. |
|
#6
|
|||
|
|||
|
I was able to handle the situation. I changed my implementation. Still I don't know why this code behaves different on Solaris and Ubuntu though...
Thanks |
|||
| Google The UNIX and Linux Forums |