리눅스 리다이렉션 c프로그래밍, 초보자 질문~

익명 사용자의 이미지

프로그래밍은 어느정도 해보았지만... 윈도우플밍
리눅스는 조금 다룰줄 아는정도였다가
리눅스에서 프로그래밍 하기시작한지 얼마안되어서 모르는게 많습니다.ㅠㅠ
도움좀 주세요ㅠㅠ

일단 c소스에서 처음으로 받는 인풋을 파일 리다이렉션으로 받고
그다음 사용자 인풋을 받으려 하는데 잘안되네요..

프로그램을 닫아야? 하는것 같은데..
예를 들어

$ ./test.c < input.in

임의의 파일에 보내고 싶은 입력값을 넣어두고 위와 같은식으로 실행시켰습니다.
파일내의 데이터를 모두 받고 나면
cout<<"Input : ";
cin>>input1;
이런식으로 사용자의 입력값을 받고 싶은데..
키보드입력을 기다려주지않고 프로그램은 끝이납니다.
물론 input1 에는 이상한값이 들어가구요ㅜㅜ
도와주세요~

익명 사용자의 이미지

input.in을 받는 부분은 어떻게 되어있나요?

크기가 일치하지 않으면 cin>>input1; 부분까지 영향을 미칠 수 있습니다.

익명 사용자의 이미지

#include

using namespace std;

int main()
{
int input;
int userin;

while(!cin.eof())
{
cin>>input;
cout< }
cout<<"userinput ? ";
cin>>userin;

cout<

return 0;
}

간단하게 짜보면 이런식으로 하려는건데요.
이상한값이 들어간다기 보다
cin>>userin;
이 부분에서의 입력을 기다려주지 않네요..

익명 사용자의 이미지

파일로부터 리다이렉트해서 cin 에서 읽으셨지요.
그 스트림에서 eof 가 읽혔다고해서 (즉, 리다이렉트된 파일을 다 읽었다고 해서) 그 다음에 cin 이 키보드 입력에 붙는 것이 아닙니다.
cin은 이제 다 끝난 스트림이고 cin 가지고 더 이상 아무것도 할 수 없습니다.

익명 사용자의 이미지

답변을 지금 보았는데
찾다보니 답해주신것처럼 더 입력을 못받는다는걸 알게 되었습니다.
리눅스에 무지하다보니...
여하튼 감사합니다^^

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.