LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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


Closed Thread
  Search this Thread
Old 03-13-2008, 02:14 PM   #1
lppc2112
LQ Newbie
 
Registered: Mar 2008
Posts: 7

Rep: Reputation: 0
Question 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;
}


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-13-2008, 09:27 PM   #2
binarybob0001
Member
 
Registered: Dec 2004
Distribution: Debian Wheezy
Posts: 444

Rep: Reputation: 30
Well, I don't know if this answers your question, but here's my shot at it.
std::vector has a push_back function which will append data to the end of the vector. Accessing elements is easy through the [] operator, and getting a total count is easy through the size() function. I think you already know this stuff; that's why I'm a little confused. I recommend you break up main into smaller functions, such as, FileManager:penFile,
FileManager::getNextVertex(), etc where FileManager is a class used to get information. This way, if there is an error somewhere, you can find out where it came from more easily. Not to mention your code will be easier to follow not just for me but for you later on. Good luck.
 
Old 03-13-2008, 09:38 PM   #3
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
Please post code in [code] tags which will preserve formatting and aid readability.

Also, this looks very much like a homework question. Please see the LQ rules for notes on that.
 
Old 03-20-2008, 10:02 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate.
 
  


Closed Thread



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
stl programming lppc2112 Programming 4 03-11-2008 04:01 AM
Hello from STL oakleyd LinuxQuestions.org Member Intro 1 12-15-2006 11:03 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 01:05 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