LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   stl programming (https://www.linuxquestions.org/questions/programming-9/stl-programming-627011/)

lppc2112 03-10-2008 12:14 PM

stl programming
 
Hello,

I have to use data structures an array or vector to store vertices in this program.

can anyone tell me how i can do it please?

#include<map>
#include<iostream>
#include<string>
#include<fstream>
#include<sstream>

using std::istringstream;
using std::ifstream;
using std::string;
using std::cout;
using std::cin;
using std::cerr;
using std::map;
using std::multimap;


int main()
{
multimap<string,int> words;
map<int,string> lines;
string str;
ifstream input("test.txt"); //create file for input
if(input.fail())
{
cerr<<"\nThe file could not be opened.";
return -1;
}
int i=1;
while(getline(input,str))
{
istringstream in(str);
string s;
while(in>>s)
{
words.insert(make_pair(s,i));
}
lines.insert(make_pair(i,str));
i++;
}
string search;
cout<<"\nEnter a word to search: ";
cin>>search;
cout<<"\nThe number of matches = "<<words.count(search)<<'\n';
multimap<string,int>::iterator it1=words.lower_bound(search);
multimap<string,int>::iterator it2=words.upper_bound(search);
while(it1!=it2)
{
int x=it1->second;
map<int,string>::iterator iter=lines.find(x);
cout<<'\n'<<x<<" ) "<<iter->second<<'\n';
it1++;
while(true)
{
if(it1!=it2 && it1->second==x)
{
it1++;

}
else
{
break;
}
}
}

cout<<'\n';

return 0;
}

Uncle_Theodore 03-10-2008 12:35 PM

/me smells homework <sniff-sniff>... :)

What "vertices" do you want to store in this program? Can you formulate the problem precisely? Why do you "have to" use "data structures" and vectors?

lppc2112 03-10-2008 12:51 PM

The final output result of the program should be a
modified obj-file.
I need the data structures (array or vector) only to
store the information, to access the data with the
algorithm and to store the modified data that will then be
written to a new obj-file

> 1. using array to store the vertices, face and normals
> 2. use array to count number of vertices, face and normals

ta0kira 03-10-2008 01:33 PM

By "object file" do you mean "a file that stores information about run-time objects"? The normal usage of "object file" describes the interim stage between compilation and linking of a program or library.
ta0kira

cicorino 03-11-2008 04:01 AM

he has to do homework about 3D data manipulation and asks us to help him to write out an 'obj' file that contains vertexes, normals, triangles etc etc.
I think he just needs something like:

struct vertex_type
{ float x,y,z;
};

struct triangle_type
{ size_t xVertexIndex, yVertexIndex, zVertexIndex;
};

typedef std::vector< vertex_type> vertexes_type;
typedef std::vector< triangle_type> triangles_type;

and so on...


All times are GMT -5. The time now is 02:12 PM.