文件I / O问题和其他功能 [英] File I/O problem and other functions

查看:47
本文介绍了文件I / O问题和其他功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿大家,

我正在为一个班级制作一个程序,我遇到了一个让我发疯的问题。我首先怀疑Vista,因为我不在家,我无法验证它是否只是我的Vista电脑,无论如何,这是问题所在。

我知道这是一个蹩脚的计划,但我缺乏创造力来提出一个程序,包括三天内所有必需的项目。我最终获得了351/585(60%)因为,我没有包含2个数组,更多用户定义的函数,我的文件I / O也不起作用。

问题是;当您在switch语句中选择选项6时,它不会停止并让您输入任何内容。它只是说输入定义,然后再次运行列表。我尝试用JUST iFile>>做到这一点其他;,那也没有用。然后我回到我的第3周任务,这是使用文件I / O并且它在这台计算机上没有工作,但在家里的桌面上运行正常,或者至少它在第3周完成。哦!它确实创建了新文件,但是不接受在文件中输出任何字符串输入。

以前,我有多个if ... else语句,而不是开关。好吧,如果我使用cin.get(var,xx)它只会显示一个空格和最后一个单词,所以而不是Hi there它只会输出有" ;. getline(cin,var)也发生了同样的事情。如果它在if ... else语句之后的任何地方,它将无法正确输出。我不得不重新安排一切,以使cin.get和getline正常工作。有谁知道为什么?


所以问题是:

文件I / O不接受字符串输入。

getline( )if if if if else语句无论多久以后都不起作用。

cin.get()在if / if ... else语句之后无论多远都不起作用之后。


它是Vista还是我,或者两者兼而有?

我想我已经下载了Vista的更新,所以它可能是也可能不是。


提前致谢

Joshua

<跨度类= codeLink 的onclick = 模糊(此,this.parentNode.parentNode,的getChildren(本),TRUE);>展开 <跨度类= codeDivider> | <跨度类= codeLink 的onclick = 全选(本);>选择 <跨度类= codeDivider> | <跨度类= codeLink 的onclick =自动换行(这);>换行 | 行号

解决方案

案例6问题:对于交互式io,您需要使用cin,而不是某些输入文件流。 Cin绑定到键盘并暂停程序,直到您输入一些值。 iFile变量将从文件中读取并且不会暂停程序。



案例6问题:对于交互式io,您需要使用cin,而不是一些输入文件流。 Cin绑定到键盘并暂停程序,直到您输入一些值。 iFile变量将从文件中读取,不会暂停程序。



我需要将字符串输入到文件中,cin>>不会这样做吗?


听起来你有两步问题。首先,使用cin将键盘中的值输入字符串。然后你用oFile把字符串放到一个输出文件中。


你不能只是从cin到oFile(至少,我从未见过用过这种方式)

Hey everyone,
I was making a program for a class, and I ran into a problem that is driving me crazy. I first suspected Vista, and since I am not home I cannot verify if it just my Vista computer, anyway, here is the problem.
I know this is a lame program, but I lacked the creativity to come up with a program including all the required items in three days. I ended up getting 351/585(60%) on this because, I didn''t include 2 arrays, more user defined functions, and my File I/O didn''t work.
The problem is; When you select option 6 in the switch statement it doesn''t stop and let you input anything. It just says enter definition, and runs the list again. I tried to do this with JUST iFile >> other;, and that didn''t work either. I then went back to my week 3 assignment which was using file I/O and it didn''t work on this computer, but on my desktop at home it runs fine, or at least it did in week 3. Oh! It does create the new file though, but just won''t accept any string input to be output INSIDE the file.
Previously, I had multiple if...else statements, instead of a switch. Well if I used cin.get(var, xx) it would only display a space and the last word, so instead of "Hi there" it would only output " there". The same exact thing happened with getline(cin, var). If it was anywhere after the if...else statements it would not output correctly. I had to re-arrange everything to get cin.get and getline to work properly. Does anyone know why?

So the problems are:
File I/O is not accepting string input.
getline() does not work after if/if...else statements no matter how far down after.
cin.get() does not work after if/if...else statements no matter how far down after.

Is it Vista or is it me, or both?
I think I downloaded the updates for Vista, so it may or may not be that.

Thanks in advance
Joshua

Expand|Select|Wrap|Line Numbers

解决方案

Case 6 problem: For interactive io, you need to use cin, and not some input file stream. Cin is tied to the keyboard and will pause the program until you input some value. The iFile variable will read from the file and will not pause the program.


Case 6 problem: For interactive io, you need to use cin, and not some input file stream. Cin is tied to the keyboard and will pause the program until you input some value. The iFile variable will read from the file and will not pause the program.

I need to input the string into the file though, cin >> will not do this will it?


It sounds like you have a 2 step problem. First, you use cin to get the value from the keyboard into the string. Then you put the string into an output file using oFile.

You can''t just go from cin to oFile (at least, I''ve never seen it used this way).


这篇关于文件I / O问题和其他功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆