UG NX二次开发源码分享:分享下关于读取文件行数的操作代码
UG NX二次开发源码分享:分享下关于读取文件行数的操作代码
以下是读文件的操作,每一行的结果存储下来!
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
const unsigned int MAX_LINES = 1024;
int main()
{
ifstream inFile;
string tmpStr("");
string *a = new string;
int index = 0;
inFile.open("./code.txt", ios::in);
if (NULL == inFile)
{
cout << "文件打开失败!" << endl;
return 1;
}
while (getline(inFile, tmpStr))
{
a = tmpStr;
index += 1;
}
for (int j = 0; j < index; j++)
{
cout << a << endl;
}
delete [] a;
return 0;
}
我在UG NX里面的代码是这样的,这样的结果就是把本地的配置文件,直接加入到UI的list 列表里面
char *path = "C:\\PLMHomeToolkits\\Configurations\\Customers.txt";
vector<NXString> CustomerValues;
string tmp("");
ifstream inFile;
inFile.open(path,ios::in);
if(NULL ==inFile)
{
uc1601("Error",1);
return ;
}
while(getline(inFile,tmp))
{
CustomerValues.push_back(tmp);
}
inFile.close();
stringCustomer->SetListItems(CustomerValues);
有用啊啊啊啊啊啊啊啊啊啊啊
页:
[1]