while-loop

How to open a file using ifstream and keep reading it until the end

泄露秘密 提交于 2019-12-11 10:39:47
问题 I simply would like to open a file named "test.txt" that contains: cat dog moose rabbit I then want to read from the file and convert its contents into strings for things that I will do later in the program. So far i think what I am doing is going in the right direction. However, I am getting an error and I am unsure what to do. Here is the Error>>> $ make -f makefile.txt g++ -g -D HASH_TABLE_SIZE=10 -c hash.cpp hash.cpp: In member function `void Hash::processFile(std::string)': hash.cpp:12:

Using While Loop instead of a For Loop in Java to ask User Input

徘徊边缘 提交于 2019-12-11 10:16:46
问题 I wrote this piece of code: Scanner askPrice = new Scanner(System.in); for(double i = 0 ; i < 3; i++); { double totalInitial = 0.00; System.out.println("Enter the price for your item. " + "Press enter after each entry. Do not type the '$' sign: ") ; double price1 = askPrice.nextDouble(); //enter price one double price2 = askPrice.nextDouble(); //enter price two double price3 = askPrice.nextDouble(); //enter price three double total = ((totalInitial) + (price1) + (price2) + (price3)); I want

Java JToggleButton freezes in While loop

瘦欲@ 提交于 2019-12-11 10:00:30
问题 public void playMet() { int tempo = Integer.parseInt(met_speed.getText()); tempo = tempo/60; int delay = tempo*1000; if(Play.isSelected()) { try { FileInputStream in = new FileInputStream(new File("Click1.wav")); AudioStream as = new AudioStream(in); AudioPlayer.player.start(as); Thread.sleep(tempo*1000); playMet(); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } else System.out.println("not playing"); } Here's a section of my code, basically when a button is pressed it

Python - Loop waiting for input

不问归期 提交于 2019-12-11 09:58:35
问题 I have looked around on the StackOverflow forums, unable to find a solution that applies to my specific problem. I need to write a bit of code, that is continuously checking for user input. I have got a Raspberry Pi with a Barcode Scanner attached to it. I want my Python script to loop, waiting for my Barcode Scanner to bleep something (which will then "type" it in the active window, it's acting like a keyboard). When the barcode scanner 'types' the 8 digit number - I need the Python script

piping output of process to sh while loop?

ぐ巨炮叔叔 提交于 2019-12-11 09:39:20
问题 I'm trying to loop over the output of a Perl process, line by line, within a while loop. However, I'm having difficulty with the syntax. I tried this, but got an "ambiguous redirect" error: #!/bin/sh while read line; do echo "$line" # do stuff with $line done < $(perl process.pl) ./script.sh : line 6: $(perl process.pl): ambiguous redirect For instance, one (inefficient) solution would be: #!/bin/sh tmpFile=/tmp/tmpFile.txt perl process.pl > $tmpFile while read line; do echo "$line" # do

Returning values from inside a while loop in python

梦想与她 提交于 2019-12-11 09:35:25
问题 I don't know if this is a simple question or impossible or anything, but I couldn't find anything on it so I figured I would ask it. Is it possible to return values from a while loop while that loop is still running? Basically what I want to do is have a vector constantly updating within a while loop, but able to return values when asked without stopping the while loop. Is this possible? Do I just have to break up the program and put the while loop in a separate thread, or can I do it within

rotate an imageView While moving it

£可爱£侵袭症+ 提交于 2019-12-11 09:23:42
问题 So I have an UIView called image, and i am trying to get it to rotate while i am moving the view up and down,here is what I've done so far,but it makes the picture rotate and not go down: { return centerY - height / 2 <= 10 || centerY + height/ 2 >= self.view.bounds.size.height - 10; } -(void)moveUpDownTimerCallback { [UIView commitAnimations]; verticalSpeed += acceleration; degrees+=degreechange; CGSize sz = image.bounds.size; image.transform = CGAffineTransformMakeRotation(degrees * M_PI

C - fscanf in while loop skips user input

时光怂恿深爱的人放手 提交于 2019-12-11 08:28:08
问题 So I run the program, it does the prints, reads the char I type from the keyboard, switches to the appropriate case, but instead of returning to the top of the loop and stopping at the fscanf in order to receive further input, it acts like it already received a new line or something and switches to the default case, returning to the top of the loop again and expecting input. What am I missing ? Here is the code: #include <stdio.h> #include <stdlib.h> #include <string.h> int main () { char

SAS: Do while loop not iterating

可紊 提交于 2019-12-11 08:24:02
问题 I have a saved csv_files SAS Dataset with the following entries: name path aapl F:\Data\aapl.csv msft F:\Data\msft.csv ibm F:\Data\ibm.csv goog F:\Data\goog.csv I then use this SAS dataset to locate the csv files and import them into SAS using the following Macro which has a while loop: options symbolgen mlogic nomprint; /*Leave options on as SAS will issue a message when Do While Loop is false*/ %let dsname = csv_files; %let libto = l; %Macro get_data(n,index); /*n: is a counting macro

jquery compare the height beneath img to h2's height

好久不见. 提交于 2019-12-11 08:18:49
问题 I am trying to adapt this: var h2=$('.block h2'); var divh=$('.block').height(); while ($(h2).outerHeight()>divh) { alert('enters while'); $(h2).text(function (index, text) { return text.replace(/\W*\s(\S)*$/, '...'); }); } as explained here: Cross browsers mult-lines text overflow with ellipsis appended within a width&height fixed div? The problem I have encountered in my case is that I have various li where each one contains a .block which has a h2 tag per li Example: <li> <div class="block