LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-10-2008, 12:14 PM   #1
lppc2112
LQ Newbie
 
Registered: Mar 2008
Posts: 7

Rep: Reputation: 0
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;
}
 
Old 03-10-2008, 12:35 PM   #2
Uncle_Theodore
Member
 
Registered: Dec 2007
Location: Charleston WV, USA
Distribution: Slackware 12.2, Arch Linux Amd64
Posts: 896

Rep: Reputation: 71
/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?
 
Old 03-10-2008, 12:51 PM   #3
lppc2112
LQ Newbie
 
Registered: Mar 2008
Posts: 7

Original Poster
Rep: Reputation: 0
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
 
Old 03-10-2008, 01:33 PM   #4
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
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
 
Old 03-11-2008, 04:01 AM   #5
cicorino
Member
 
Registered: May 2006
Location: Italy
Distribution: Slackware, Slackware64
Posts: 31

Rep: Reputation: 16
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...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Hello from STL oakleyd LinuxQuestions.org Member Intro 1 12-15-2006 11:03 PM
A query regarding STL ankit4u1 Programming 8 05-30-2006 04:22 PM
about STL programming wangjinyi Programming 2 03-24-2005 05:45 PM
c++ and stl G67 Programming 4 12-17-2003 02:36 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration