在VC ++中读取文本文件 [英] Reading text file in VC++

查看:109
本文介绍了在VC ++中读取文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我是C ++的新手,并且有一个新项目.
我有一个文本文件,其数字为坐标x,y
文本文件的格式如下:
X Y

234 5678
243 3456
193235
1234 345
等等
步骤,
1.-将所有这些文件放入缓冲存储器(unsigned char inbuffer [2000],
2.-在两个文本框中显示每两个坐标,一个用于X,一个用于Y(我不知道该怎么做)
3.- inbuffer [0] = outbuffer [0]
inbuffer [1] = outbuffer [1]
4.增量inbuffer + 2用于下两个坐标
5.-将此数据放入USB(已解决)
6.-微控制器发送就绪位以接收更多数据(已解决)
7.-从第2步开始重复,直到发送完所有数据.
非常感谢您的帮助,并提供了一些代码.
问候
Carlos

Hello every one,
I am new in C++ and I have a new project.
I have a text file with numbers that are coordinates x,y
The text files´s format looks like this:
X Y

234 5678
243 3456
193 235
1234 345
and so on
Steps,
1.- Put all this file in a buffer memory (unsigned char inbuffer [2000],
2.- Display each two coordinates in two text box one for X and one for Y (I dont´t know how to do this)
3.- inbuffer [0] = outbuffer[0]
inbuffer [1] = outbuffer[1]
4.-increment inbuffer + 2 for next two coordinates
5.-Put this data in USB (Resolved)
6.-Microcontroller sends ready bit to receive more data (resolved)
7.-Repeat from step 2 until all data is sended.
I really appreciate your help with a little code.
Regards
Carlos

推荐答案

使用ifstream::open以读取模式打开文件.
使用getline一次读取一行文件.
使用strtok_s将每行以空格作为分隔符分为X和Y.
Use ifstream::open to open the file in read mode.
Use getline to read the file one line at a time.
Use strtok_s to split each line into X and Y with space as the delimiter.


我会尽力而为, CARLOS
I will try his way, thanks a lot
CARLOS


您还可以检查CStdioFile MFC类以访问文件.
you can also check CStdioFile MFC class for accessing file.


这篇关于在VC ++中读取文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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