Page 1 of 1

Help me to write a C++ program

Posted: Wed Jul 19, 2006 11:49 am
by Sitha
Hi,
I am new to C++ program, Pls help me for following probelm.
I have a text file as following,
DYNAMIC ANALYSIS
次元数 ケース 内部加振 活荷重
3 1 0 0
KACC KDIS KSTS KSTN KSSR KJOT KNOD KRAT KSEC KMSS KWPR
7 7 14 14 0 14 1 0 0 1 0
FREQ GFREQ EXMAX
0.0 2.00 1.0D-6
VISCOUS BOUNDARY INFORMATION
3 2.00
77 60 11 66
0 0
加速度時刻歴出力節点番号(KACC=0.OR.>NTJの場合,削除)
1080 1254 1484 1549 1563 1592 1608
JOINT挙動出力要素番号(KJOT=0.OR.>JOINTの場合,削除)
7 8 20 22 117 118 127
128 129 130 133 134 139 140
NODES
1 -101.582 -234.742 280.000 3
2 -76.838 -234.742 280.000 3
3 -54.479 -234.742 280.000 3
4 -34.276 -234.742 280.000 3
5 -16.020 -234.742 280.000 3
6 0.476 -234.742 280.000 3
7 19.063 -234.742 280.000 3
8 37.649 -234.742 280.000 3
9 72.755 -234.742 280.000 3
10 112.781 -234.742 280.000 3
11 158.418 -234.742 280.000 3

Now I want to extract only nodes from this file and put them into another text file as follows,

101.582 -234.742 280.000
-76.838 -234.742 280.000
-54.479 -234.742 280.000
-34.276 -234.742 280.000
-16.020 -234.742 280.000
0.476 -234.742 280.000
19.063 -234.742 280.000
37.649 -234.742 280.000
72.755 -234.742 280.000
112.781 -234.742 280.000
158.418 -234.742 280.000
I should omit all the setences and other details, I only need coordinates of nodes in another text file. Pls help me how to write a program.

Regards,
Sitha.


I tried following program, but it didnt work well. Pls help me !!!!!!!!!!

////////////////////////////////////////////////////////////////////////////////////

#include <fstream>
#include <iostream>
#include <String>
#include <sstream>

using namespace std;

int main()
{
char filename[15];
bool found=false;
string buff;
cout<<"Enter your file name: ";
//save the file name
cin>>filename;
// open the input file
ifstream input(filename);
if(!input)
{
cout<<"can't open the file"<<endl;
}
else
{
// open a file for output
ofstream output;
// output file name
output.open("nodes.txt");
while(!input.eof())
{
getline(input,buff);
// if the line is read as NODES
if (buff.compare("NODES")==0)
{
// start to read and output the following lines
while(!input.eof())
{
getline(input,buff);
istringstream tmp(buff);
// format the output
string first,second,third,fourth,fifth;
tmp>>first>>second>>third>>fourth>>fifth;
output<<second<<" "<<third<<" "<<fourth<<endl;
}
found=true;
cout<<"Nodes found and outputed"<<endl;
break;
}

}
output.close();
}
if (found==false)
cout<<"No node found in the file"<<endl;
input.close();
system("pause");
}

///////////////////////////////////////////////////////////////////////////////////////

Re: Help me to write a C++ program

Posted: Mon Oct 06, 2008 4:54 pm
by lnr
Your problem is not clear.
Tell about the coordinates in detail.