stl
how do i use data structures, array or a vector to store some vertices??
how to implement in the program and where?
here is my code
#include<map>
#include<iostream>
#include<string>
#include<fstream>
#include<sstream>
#include <vector>
using std::istringstream;
using std::ifstream;
using std::string;
using std::cout;
using std::cin;
using std::cerr;
using std::map;
using std::multimap;
using namespace std;
/*struct obj
{
float x,y,z;
};
obj vertices,face,normals
vertices.x
face.y
normals.z
*/
int main()
{
multimap<string,int> words;
map<int,string> lines;
string str;
ifstream input("rohr1.obj"); //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;
}
|