•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 374,017 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,675 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 11080 | Replies: 2
![]() |
•
•
Join Date: Dec 2004
Location: Hong Kong, SAR
Posts: 22
Reputation:
Rep Power: 4
Solved Threads: 1
Dear all,
Forgive me for posting two threads for the same problem. I was not showing my problem clearly enough in the previous one. Thank Narue for answering that anyway. Now I do it again here:
This programme runs fine when I compile and click the executable. But things go wrong if I do it in command-line and redirect the input stream to a text file:
$a.out < inputFile
*The programme does not let me do any input and it loops again and again instead.* I guest this is a problem associated with getline() function.
So what do you think about this?
Jim
Forgive me for posting two threads for the same problem. I was not showing my problem clearly enough in the previous one. Thank Narue for answering that anyway. Now I do it again here:
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
string inputStr;
while (true)
{
getline(cin, inputStr);
if (inputStr == "quit") break;
cout << inputStr << endl;
}
return 0;
}This programme runs fine when I compile and click the executable. But things go wrong if I do it in command-line and redirect the input stream to a text file:
$a.out < inputFile
*The programme does not let me do any input and it loops again and again instead.* I guest this is a problem associated with getline() function.
So what do you think about this?
Jim
•
•
•
•
Originally Posted by jimFan
This programme runs fine when I compile and click the executable. But things go wrong if I do it in command-line and redirect the input stream to a text file:
$a.out < inputFile
Or do you mean to redirect the output to a file?
$a.out > inputFile•
•
Join Date: Dec 2004
Location: Hong Kong, SAR
Posts: 22
Reputation:
Rep Power: 4
Solved Threads: 1
•
•
•
•
Originally Posted by Dave Sinkula
Don't you mean input from? What are the contents of your input file?
Or do you mean to redirect the output to a file?$a.out > inputFile
Hi Dave,
Oh sorry for my grammer. I actually mean input from:
$a.out < inputFile
Here is what the content of inputFile maybe:
ls changecc COMP271 5 quiz quit
The problem occur when the programme has read all the way to the last line:
The programme loops and does not ask me for input.
Jim
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
Similar Threads
- How could I break an infinite loop?? (Assembly)
- Help Me Solve My Infinite Loop (C++)
- How do you Terminate an Infinite Loop? Impossible!!! (C++)
- infinite loop... (C++)
- infinite loop (C)
- Someone Be My Program Study Buddy (C++)
- infinite loop (C++)
Other Threads in the C++ Forum
- Previous Thread: system("PAUSE")
- Next Thread: need to find occurances in a string



Linear Mode