请教:关于文件的读取问题,在线等待!!!

shen_wei 2011-02-19 11:05:53
[code=C]
22.628269 114.034432,22.628269 114.034442,22.628269 114.034452,22.628269 114.034462,22.628269 114.034472,22.628269 114.034482,22.628269 114.034492,22.628269 114.034502,22.628269 114.034512,22.628269 114.034522,22.628269 114.034532,22.628269 114.034542,22.628269 114.034552,22.628269 114.034562,22.628269 114.034572,22.628269 114.034582,22.628269 114.034592,22.628269 114.034602,22.628269 114.034612,22.628269 114.034622,22.628269 114.034632,22.628269 114.034642,22.628269 114.034652,22.628269 114.034662,22.628269 114.034672,22.628269 114.034682,22.628269 114.034692,22.628269 114.034702,22.628269 114.034712,

以上是文本的内容。。。。
[/code]
[code=C]
struct Coordinate
{
Char latitude[10];
Char longitude[10];
};
[/code]
如上面:这样的一个文本内容, 现在内容已经读取到了CString类型的变量中,怎么做才能把内容的中的数据给保存到数组结构体中?

Coordinate m_point;
m_point[0].latitude = 22.628269;
m_point[0].longitude = 114.034432;

等等这样一次类推。。。

1.现在不知道文本中有多少个这样结构体。。怎么给结构体申请足够的内存空间??
2.用什么方法才能更快速的把字符串中数据给写到数组结构体中??

谢谢大家提供代码或者意见!!
...全文
91 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
shen_wei 2011-02-19
  • 打赏
  • 举报
回复
code=HTML]CSDN出问题了。。。。[[/code]
shen_wei 2011-02-19
  • 打赏
  • 举报
回复
[code=C]CString s;
s = strdata1[i].Right(len+1);
strcpy(data.longitude,s);
marry.Add(data);//[/code]
我看看你的代码。。STL不熟悉。。
还在查 2011-02-19
  • 打赏
  • 举报
回复
怎么发出来还是这样的呢
还在查 2011-02-19
  • 打赏
  • 举报
回复
[code=C]
struct Coordinate
{
char latitude[10];
char longitude[10];
};

CArray <Coordinate,Coordinate> marry;

void Split(CString source, CStringArray& dest, CString division)
{
int pos = 0;
int pre_pos = 0;
dest.RemoveAll();
pos = source.Find(division);
if(pos == -1)
dest.Add(source);
else
{
dest.Add(source.Left(pos));
pre_pos = pos;
pos = source.Find(division, pos+1);
while( -1 != pos ){
dest.Add(source.Mid(pre_pos+1,(pos-pre_pos-1)));
pre_pos = pos;
pos = source.Find(division, pos+1);
}
dest.Add(source.Right(source.GetLength() - pre_pos - 1));
}
}
BOOL CtestbugDlg::OnInitDialog()
{
CStdioFile file;
file.Open("1.txt",CFile::modeRead);
CString dest;
CString str;
while(file.ReadString(str))
{
dest += str;
}
CStringArray strdata1,strdata2;
Split(dest,strdata1,",");

for (int i=0;i <strdata1.GetSize();i++)
{
Split(strdata1[i],strdata2," ");
Coordinate data;

strcpy(data.latitude,strdata2[0]);
int len = strdata2[0].GetLength();
CString s;
s = strdata1[i].Right(len+1);
strcpy(data.longitude,s);
marry.Add(data);//marry就是结构体数据
}
}



[/code]
还在查 2011-02-19
  • 打赏
  • 举报
回复
[code=C]
struct Coordinate
{
char latitude[10];
char longitude[10];
};

CArray<Coordinate,Coordinate> marry;

void Split(CString source, CStringArray& dest, CString division)
{
int pos = 0;
int pre_pos = 0;
dest.RemoveAll();
pos = source.Find(division);
if(pos == -1)
dest.Add(source);
else
{
dest.Add(source.Left(pos));
pre_pos = pos;
pos = source.Find(division, pos+1);
while( -1 != pos ){
dest.Add(source.Mid(pre_pos+1,(pos-pre_pos-1)));
pre_pos = pos;
pos = source.Find(division, pos+1);
}
dest.Add(source.Right(source.GetLength() - pre_pos - 1));
}
}
BOOL CtestbugDlg::OnInitDialog()
{
CStdioFile file;
file.Open("1.txt",CFile::modeRead);
CString dest;
CString str;
while(file.ReadString(str))
{
dest += str;
}
CStringArray strdata1,strdata2;
Split(dest,strdata1,",");

for (int i=0;i<strdata1.GetSize();i++)
{
Split(strdata1[i],strdata2," ");
Coordinate data;

strcpy(data.latitude,strdata2[0]);
int len = strdata2[0].GetLength();
CString s;
s = strdata1[i].Right(len+1);
strcpy(data.longitude,s);
marry.Add(data);//marry就是结构体数据
}
}
[/code]
做鸡真好吃 2011-02-19
  • 打赏
  • 举报
回复
vector<Coordinate>

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧