JoBe 36 Posting Pro in Training

Does anyone know of a college in Georgia that offers a complete online BS in Game Development or Computer Science?

Think you'd better ask that question at the GameDev forums

JoBe 36 Posting Pro in Training

Hello ladies and gents,

I'm trying to include a copy constructor and an assignement operator into this code wich has two separate classes, the idea is to copy the last name that was entered. Problem is, I can't seem to grasp how to get acces to the copy constructor in main nor am I sure that the copy constructor is written correctly?

Could someone help me out with this program:

//Lobby
//Simulate a lobby where people wait

#include <iostream>
#include <string>

using namespace std;

class Person
{
public:
    Person(const string& name = ""):m_Name(name), m_pNext(NULL){}
    Person(const Person& copyName);
    string GetName() const { return m_Name;}
    Person* GetNext() const { return m_pNext;}
    void SetNext(Person* next) { m_pNext = next;}
    
private:
    string m_Name;
    Person* m_pNext;    // pointer to next name in list
};

Person::Person(const Person& copyName)
{
    cout << "Copy constructor called...\n";
    
    m_pNext = new Person;
    *m_pNext = copyName.GetName();
}

class Lobby
{
    friend ostream& operator<<(ostream& os, const Lobby& aLobby);

public:
    Lobby():m_pHead(NULL){}
    ~Lobby() { Clear();}
    
    void AddName();
    void RemoveName();
    void Clear();
    
private:
    Person* m_pHead;
};

void Lobby::AddName()
{
    //create a new name node
    cout << "Please enter the name of the new person: ";
    string name;
    cin >> name;
    Person* pNewName = new Person(name);
    
    //if list is empty, make head of list this new name
    if (m_pHead == NULL)
    {
        m_pHead = pNewName;
    }
    //otherwise find the end of the list and add the name there
    else
    {
        Person* pIter = m_pHead;
        
        while (pIter->GetNext() != NULL)
        {
                pIter = pIter->GetNext();
        }
JoBe 36 Posting Pro in Training

Thanks Narue, that explanation made it very clear why it happens :!:

How do you actually know when to use cin.get() or cin.ignore()
or another.

Because as you said, when I used the cin.ignore(cin.rdbuf()->in_avail() + 1) piece of code, depending on wich program I was trying out, it either worked or it didn't and I had to add a cin.get() to it or not.

Ive read several posts about it, but none actually have ever really explained how you determine what to use in your program ?

JoBe 36 Posting Pro in Training

Hello ladies and gents,

I was trying to write a small example of a pointer to a two dimensional array like this after looking up how to write the syntax at Narue's Et.Conf. world like this:

#include <iostream>
#include <iomanip>

void array(short (*myArray)[4][4]);

using namespace std;

int main()
{	
	short Map[4][4] = {0};
	short (*pMap)[4][4] = &Map;

	array(pMap);

	cout << "Press enter to exit\n";

	cin.ignore(cin.rdbuf()->in_avail() + 1);
	
    return 0;
}

void array(short (*myArray)[4][4])
{
	
	short size = sizeof myArray[0]/ sizeof myArray[0][0];

	for (int i = 0; i < size; i++)
		for (int j = 0; j < size; j++)
		{
			cout << (*myArray)[i][j] << " ";
			if (j%4 == 3) cout << endl;
		}
}

Works like a charm, though, when I wrote *myArray[j] instead of (*myArray)[j], the output was that the first row was all 0, but the rest were random numbers :-|

Can someone tell me why this happens :?:

Thanks for the help,

JoBe 36 Posting Pro in Training

Do this

//Constructor
CBooks()[COLOR=Red]{}[/COLOR];

You hadn't defined the Constructor. Only declared it.

And remove the semicolon:

CBooks(){};
JoBe 36 Posting Pro in Training

Some light reading:
http://ldeniau.home.cern.ch/ldeniau/html/oopc/oopc.html :p

OH BOY :mrgreen:

If you call that light reading, I'd hate to see you give a link to heavy :lol:

Hope you don't mind, I'm going to save this for a later date, first start reading Accelerated C++ ;)

Thanks anyway and Happy New Year :!:

JoBe 36 Posting Pro in Training

Hello ladies and gents,

I hope the moderators won't mind me posting this here, if they do, feel free to move it, but since it is related towards C++, I figured it belonged here ;)

A while back I was browsing the GameDev forums and I found this thread in wich someone announced some vid tutorials about a tutorial in C++ for writing a text RPG game. Now, keep in mind, this person wrote this tutorial without any preparation other then a word document in wich he documented all the variables (monsters, potions, spells, attack- defend parameters, etc...) he would use.

I'm sure you pro's and even advanced hobbyists will go like: Oh my, what the hell is he doing there, ... but for those of us who are actual beginners in programming and feel that alltough we are beginning to get a grasp of C++, it still is very much abstract as to how something can be incorporated into a real programm that actually does something then those endless lines of code you write or read in books and online tutorials.

For instance, at a certain moment, he has two classes, one PLAYERS and one MONSTERS, he has written them both, but then explains that there are several variables that both use and he could create another class in wich the variables wich are used for both can be stored and voila, you have your inheritance, now, alltough I understand inheritance and what the meaning …

JoBe 36 Posting Pro in Training

Hello ladies and gents,

I was just wondering how you would implement this into C if it actually is possible, if not, how do you guys implement an equal way of dealing with this in C ?

For instance, if you would have classes like this in C++:

class Lightwave
{
	...
};

class Modeler : public Lightwave
{
	...
};

class Layout : public Lightwave
{
	...
};

int main()
{
	cout << "Press enter to exit.\n";;

	cin.ignore(cin.rdbuf()->in_avail() + 1);

	return 0;
}

Is it all done with structures then?

JoBe 36 Posting Pro in Training

Tried combining those for loops?

No, I didn't, but then again, it wasn't really needed since it was just an example, but thanks for mentioning it ;)

JoBe 36 Posting Pro in Training

...and everyone else who's unlucky enough to read your code. ;)

LOL :lol:

Thanks for the explanation ;)

And a Happy New Year :!:

JoBe 36 Posting Pro in Training

Parens are there because a lot of people have trouble with the associativity of operators that have equal precedence. It's right to left in this case, so you can safely remove the parens if you want and the dereference is still performed first.

Thanks Narue,

One question if you don't mind, I tried it with and without parenthesis (<-- spelling?) and like you said it worked perfectly.

But, when I tried to do this postfix without parenthesis, the program just stayed in an endless loop, but not when using parenthesis.

Have you any idea why it is important to use parenthesis when using postfix?

Maybe I know the answer because you allready gave it --> because of the dereferencing (associativity of operators)?

JoBe 36 Posting Pro in Training

Hello ladies and gents,

Wondered if any of you could help me out here, I'm trying to increment an element of a vector of integers. Here's the code:

#include <algorithm>
#include <cctype>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
	vector<int> scores;
	scores.push_back(500);
	scores.push_back(600);
	scores.push_back(300);

	vector<int>::iterator iter;

	for (iter = scores.begin(); iter != scores.end(); ++iter)
		cout << *iter << endl;

	for (iter = scores.begin(); iter != scores.end(); ++iter)
		???????? // what do I put here

	for (iter = scores.begin(); iter != scores.end(); ++iter)
		cout << *iter << endl;

	cout << "Press enter to exit.\n";;

	cin.ignore(cin.rdbuf()->in_avail() + 1);

	return 0;
}

My idea is to increment the scores by 1 so that the values are:
501
601
301

How can I do that?

Any help would be appreciated :D

JoBe 36 Posting Pro in Training

Narue's site? Where would I find that at?

Here ya go: The Eternally Confuzzled World of Narue :mrgreen:

JoBe 36 Posting Pro in Training

I do that a lot too :lol:

And I thought you guys didn't have anything left to learn :lol:

JoBe 36 Posting Pro in Training

well, the allocating is done for every separate class (dog, cat, horse, ...) so, they aren't separate functions but, separate classes wich have Mammal as there base class.

Using the for loop, haven't I deleted every memory allocation that was used for the new pointers? So, why should I delete the ptr aswell, it was stored in the array, or am I wrong at this?

Could be winbatch, just trying to figure this out you know :)

JoBe 36 Posting Pro in Training

Hmmm, think I'm wrong here, think it's got to do with the fact that theArray is an object to Mammal, therefore, deleting theArray's memory is linked towards the Mammal's destructor right :?:

JoBe 36 Posting Pro in Training

Wow, just noticed that the Mammals destructor is allways called, is this because Mammal is the base class and it has the virtual Speak(); function :?:

JoBe 36 Posting Pro in Training

Ok, will do :!:

JoBe 36 Posting Pro in Training

brackets are in the wrong place

for( i = 0; i < 5; i++)
     delete theArray[i];

Darn :mrgreen:

Thanks Ancient Dragon ;)

JoBe 36 Posting Pro in Training

Hello ladies and gents,

Ive been reading about Virtual Function in my book and there is this programming that shows how and what happens, I understand what is happening but one thing that came to my mind is that, previously in my book, there was mentioned that you should allways "delete" the memory that was allocated with "new". However, this is not done in this program and I understand why, it's just a small program to show the virtual function.

Still, I was wondering how one would do this as the memory allocation is done for an Array of Mammals :?:

#include <iostream>

class Mammal
{
public:
	Mammal():itsAge(1) {}
	~Mammal() {}

	virtual void Speak() const { std::cout<<"Mammal speak!\n";}

protected:
	int itsAge;
};

class Dog : public Mammal
{
public:
	void Speak() const { std::cout<<"Woof!\n";}
};

class Cat : public Mammal
{
	void Speak() const { std::cout<<"Meow!\n";}
};

class Horse : public Mammal
{
	void Speak() const { std::cout<<"Hihihi!\n";}
};

class Pig : public Mammal
{
	void Speak() const { std::cout<<"Oinkoink!\n";}
};

int main()
{
	Mammal *theArray[5];
	Mammal *ptr;

	int choice, i;

	for( i = 0; i < 5; i++)
	{
		std::cout<<"(1)dog (2)cat (3) horse (4) pig: ";
		std::cin>> choice;

		switch(choice)
		{
		case 1:
			ptr = new Dog;
			break;
		case 2:
			ptr = new Cat;
			break;
		case 3:
			ptr = new Horse;
			break;
		case 4:
			ptr = new Pig;
			break;
		default:
			ptr = new Mammal;
			break;
		}

		theArray[i] = ptr;
	}

	for( i = 0; i < 5;
JoBe 36 Posting Pro in Training


j++ means j == j +1

I think you ment j = j + 1 right :?:

JoBe 36 Posting Pro in Training

You obviously don't test your code before you post, ...

and doesn't read the whole thread, otherwise, he would have seen that this solution was allready given and wasn't the solution the thread starter was looking for :!:

JoBe 36 Posting Pro in Training

you can also use

system("pause" );

statement before the return statement to make the program pause till you press a key.

I thought Ive read on several occasions that this should be avoided since it is bad programming :?:

JoBe 36 Posting Pro in Training

Hmm, well, the only way I can think of is this way:

#include <iostream>

using namespace std;

int main()
{
	char ch = 'j';

	for (;;)
	{
		cout<<"Hello!\n";

		cin>> ch;

		if(ch == 'Q') break;
	}

	return 0;
}
JoBe 36 Posting Pro in Training
#include <iostream>

using namespace std;

int main()
{
	int stop = 0;

	while (true)
	{
		stop++;

		cout<<"Hello!\n";

		if(stop == 5) break;
	}

	return 0;
}

OR

#include <iostream>

using namespace std;

int main()
{
	int i = 0;

	for(;;)
	{
		i++;
		cout<<"Hello!\n";

		if (i == 5) break;
	}

	return 0;
}

Hope this helps :D

One other thing, when posting code use code tags like this:

[ code ]code in here [ /code ] but without the space between the square brackets :!:

JoBe 36 Posting Pro in Training

Doh, how stupid I have been :o

JoBe 36 Posting Pro in Training

Thank you sunnypalsingh for your help :!:

Could you however explain why it is necessary to write the name of the class infront of the definition inside the class and twice infront of the declaration outside the class :?:

JoBe 36 Posting Pro in Training

Hello ladies and gents,

I was reading about how "Passing by References" for efficiency and there was a little program added wich shows what the difference is between passing by value and passing by reference is. The program is this one:

#include <iostream>

using namespace std;

class SimpleCat
{
public:
	SimpleCat();
	SimpleCat (SimpleCat&);
	~SimpleCat();
};

SimpleCat::SimpleCat()
{
	cout<<"Simple Cat Constructor...\n";
}

SimpleCat::SimpleCat (SimpleCat&)
{
	cout<<"Simple Cat Copy Constructor...\n";
}

SimpleCat::~SimpleCat()
{
	cout<<"Simple Cat Destructor...\n";
}

SimpleCat FunctionOne (SimpleCat theCat);
SimpleCat *FunctionTwo (SimpleCat *theCat);

int main()
{
	cout<<"Making a cat...\n";
	SimpleCat Frisky;
	cout<<"Calling FunctionOne...\n";
	FunctionOne (Frisky);
	cout<<"Calling FunctionTwo...\n";
	FunctionTwo (&Frisky);
	
	return 0;
}

SimpleCat FunctionOne (SimpleCat theCat)
{
	cout<<"FunctionOne returning...\n";
	
	return theCat;
}

SimpleCat *FunctionTwo (SimpleCat *theCat)
{
	cout<<"FunctionTwo returning...\n";

	return theCat;
}

No problem there, but, I decided to see wether I could change the program so "FunctionOne" and "FunctionTwo" where memberfunctions from SimpleCat, but, to no avail.

I thought that the following changes would be correct and lett me use this in the same way as the above example, but, that is not the case:

#include <iostream>

using namespace std;

class SimpleCat
{
public:
	SimpleCat();
	SimpleCat (SimpleCat&);
	~SimpleCat();

	FunctionOne (SimpleCat);
	*FunctionTwo (SimpleCat*);
};

SimpleCat::SimpleCat()
{
	cout<<"Simple Cat Constructor...\n";
}

SimpleCat::SimpleCat (SimpleCat&)
{
	cout<<"Simple Cat Copy Constructor...\n";
}

SimpleCat::~SimpleCat()
{
	cout<<"Simple Cat Destructor...\n";
}

int main()
{
	cout<<"Making a cat...\n";
	SimpleCat Frisky;
	cout<<"Calling FunctionOne...\n";
	Frisky.FunctionOne (Frisky);
	cout<<"Calling FunctionTwo...\n";
	Frisky.FunctionTwo (&Frisky);
	
	return 0;
}

SimpleCat::FunctionOne( SimpleCat theCat)
{
	cout<<"FunctionOne returning...\n";
	
	return theCat;
}

SimpleCat::*FunctionTwo (SimpleCat *theCat)
{
JoBe 36 Posting Pro in Training

Well, I don't post that often, just when I have a problem with C++ that I can't figure out.

I frequently visit the DaniWeb forum (C++) and it's actually the only one I visit though I now several other ones!

Reason is because, the outlay is great (wonderfull job you did on that Dani) and the people are very helpfull :!:

I also like to read the threads in the C++ forum to see what questions others have and see how others then help them out, it's just fun to read it :)

JoBe 36 Posting Pro in Training
#include <iostream>

using namespace std;

int main()
{
char ch = 'j';
  
	while(ch == 'j' || ch == 'J')
	{
		cout << "Enter height in centimeters: ";
		int centimeters;
		cin >> centimeters;
		cout << "Your height in feet " << centimeters << endl;

		cout<<"Wish to enter a new number? Press j or J to continue!\n"
			  "Press any other key to quit!\n";

		cin>> ch;
	}

	cout<<endl;

	return 0;
}

Hope this helps ;)

JoBe 36 Posting Pro in Training

Eternally confuzzled ... my favorite site :)

DITO :D

JoBe 36 Posting Pro in Training

Ah, ok thanks, that worked :) Strange that it isn't mentioned in the book though, they only talk about <numeric> :rolleyes:

Does the example work because <list> contains <functional> :?:

JoBe 36 Posting Pro in Training

That's exactly what was written in my book, the only thing is, if I use

partial_sum(a, a+4, b, multiplies<long>());

without <list>, it doesn't work :confused:

I get two errors:

Compiling...
main.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\LAVbBoek\main.cpp(13) : error C2065: 'multiplies' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\LAVbBoek\main.cpp(13) : error C2062: type 'long' unexpected
Error executing cl.exe.

main.obj - 2 error(s), 0 warning(s)

JoBe 36 Posting Pro in Training

Thanks for your example Stoned_coder, but that wasn't really my question ;)

What I want to know is wich is the correct header file for using partial_sum, <list> or <vector>, but, I think Ive got it since I'm able to use <list> for both versions and not <vector> :!:

JoBe 36 Posting Pro in Training

Hello ladies and gents,

I'm reading about the algorithm partial_sum and there are two different versions of this.

The first one just calculates cumulative numbers like this:

#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

int main()
{
	int a[4] = {10, 20, 30, 40}, b[4];

	partial_sum(a, a+4, b);

	copy(b, b+4, ostream_iterator<int>(cout, " "));
	cout<<endl;

	cout<<"Press any key to continue!\n";
	cin.get();

	return 0;
}

The second one can be used for other algorithmetic reasons, like multiplying for example:

#include <iostream>
#include <numeric>
#include <list>

using namespace std;

int main()
{
	long a[4] = {10, 20, 30, 40}, b[4];

	partial_sum(a, a+4, b, multiplies<long>());

	copy(b, b+4, ostream_iterator<long>(cout, " "));
	cout<<endl;

	cout<<"Press any key to continue!\n";
	cin.get();

	return 0;
}

The questions I have though are:

1) I can't seem to be able to use the second version with #include <vector>, why is that?
2) How can I know wich header file is exactly needed for this?

JoBe 36 Posting Pro in Training

Ah, ok, I understand, I changed the last 8 into 9 and it gave me four as result for 'p2 - a'.

Thanks Narue :!:

JoBe 36 Posting Pro in Training

Thanks for the additional information gentlemen :!:

Ive got another question and alltough it's not related to <map>, it is related towards STL.

There's a program shown in wich the uses of find_first_of and find_end are explained, now, I understand what find_first_of is doing, but can't figure out what the actual function of find_end is :confused:

#include <algorithm>
#include <iostream>

using namespace std;

int main()
{
	int a[10] = {3, 2, 5, 7, 5, 8, 7, 5, 8, 5},
		b[2] = {5, 8}, *p1, *p2;

	p1 = find_first_of(a, a + 10, b, b + 2);
	p2 = find_end(a, a + 10, b, b + 2);

	cout<< p1 - a <<" "<< p2 - a <<endl;
	
	cout<<"Press any key to continue!\n";
	cin.get();

	return 0;
}

Output: 2 7

I understand where 2 comes from because comparing a[5] with b[5] puts it on the second place of a, starting from 0.

But, how does 7 becomes the output for find_end, I don't understand, is it also a position that is determined :?:

The explanation that is given isn't really clear and doesn't really make sense, could someone explain what find_end actually does :?:

JoBe 36 Posting Pro in Training

Thanks Narue ;)

JoBe 36 Posting Pro in Training

Hello ladies and gents,

Im reading about working with maps and there is small programm example shown in this chapter. Now, when I write this code into the MS VC C++ compiler and compile the code, I get like over 90 warnings, however, when pressing compile again, they all are gone :?:

#include <iostream>
#include <string>
#include <map>

using namespace std;

int main()
{
	typedef map<string, int, less<string> > maptype;
	maptype M;

	M["Jan"]   = 1234;
	M["Piet"]  = 9999;
	M["Piet"]  = 3456;
	M["Klaas"] = 5678;

	for(maptype::iterator i = M.begin(); i != M.end(); ++i)
		cout<< (*i).first <<" "<< (*i).second <<endl;

	cout<<"Press any key to continue!\n";
	cin.get();

	return 0;
}

Some examples of warning messages:

main.cpp
c:\program files\microsoft visual studio\vc98\include\xtree(120) : warning C4786: 'std::_Tree<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const ,
int>,std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,int,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<int> >::_Kfn,std::less<std::basic_string<char,std::char_traits<cha
r>,std::allocator<char> > >,std::allocator<int> >' : identifier was truncated to '255' characters in the debug information
        c:\program files\microsoft visual studio\vc98\include\map(46) : see reference to class template instantiation 'std::_Tree<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::pair<std::basic_string<char,std::char_traits<
char>,std::allocator<char> > const ,int>,std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,int,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<int> >::_Kfn,std::less<std::ba
sic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<int> >' being compiled
        C:\Program Files\Microsoft Visual Studio\MyProjects\LAVbBoek\main.cpp(12) : see reference to class template instantiation 'std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,int,std::less<std::basic_string<char,std
::char_traits<char>,std::allocator<char> > >,std::allocator<int> >' being compiled

Questions are:

1) What is causing these warnings the first time I compile?
2) How can I make sure that these warnings aren't shown from the first time I compile the code?
3) Why do those warnings don't appear the second time I compile this code?

JoBe 36 Posting Pro in Training

Hi Narue,

I was just wondering wether you guys ever thought about adding several Post Icons stating wether the questions is related towards C, C++ or additional on compilers, etc...

Probably you'll think that this will be forgotten more then it'll be used, then maybe the forum can be altered so that before you actually can create a new thread, you have to choose between one of these choises?

Don't know of course if this would be alot of work to change this?

JoBe 36 Posting Pro in Training

@ Narue, I used the second example in this thread to try it out.

@ Paul.Esson, yep, that worked like a charm, tried it out with a Word document and I really got a bunch of gunk, then made a test document with notepad in wich I entered several sentences, worked like a charm :!:

Going to try some stuff out now and see how the code responds :cheesy:

Thank you all for your time and effort :)

JoBe 36 Posting Pro in Training

Hi Narue,

Cut and paste, then Ctrl + F5 and typed in C:\Sol.AKN, it gave the same message as before :confused:

[IMG]http://img287.imageshack.us/img287/6196/directorysol6hk.jpg[/IMG]

JoBe 36 Posting Pro in Training

Hi zyruz,

You mean like this:
C:\DocumentsandSettings\JohanBerntzen\Mijndocumenten\Sollicitaties\Sol.AKN

Yep, tried it, no luck.

Also tried,

C:\documentsandsettings\johanberntzen\mijndocumenten\sollicitaties\sol.akn

C:/DocumentsandSettings/JohanBerntzen/Mijndocumenten/Sollicitaties/Sol.AKN

C:\DocumentsandSettings\JohanBerntzen\Mijndocumenten\Sollicitaties\SolAKN

C:/Documents and Settings/Johan Berntzen/Mijn documenten/Sollicitaties/Sol.AKN

C:\Sol.AKN

C:\solakn

Not one was correct :confused:

And the path exists, I'm 100% certain about that :!:

JoBe 36 Posting Pro in Training

Pffffffff, I don't understand, when I execute the program with Ctrl + F5 and then enter the correct path: C:\Documents and Settings\Johan Berntzen\Mijn documenten\Sollicitaties\Sol.AKN

I allways get the message "Can't open the inputfile" :?:

Sol.AKN is a word document, has this got something to do with it?
I want to use this because it has text written in it, this way It can determine wich the largest alinea is in this text.

I'm obviously doing something wrong, but what :-|

JoBe 36 Posting Pro in Training

>Yes, any valid path can be used as a file name, and sometimes the full path must be used, for example, if I remember correctly if the file to open isn't in the same directory as the file that contains the compiler then you must use the full path to the file to open.

Ok, just imagine that this is the file I wanted to work with: C:\Documents and Settings\Johan Berntzen\Mijn documenten\Solicitaties\Sol.Devlop

Can I enter this during the execution of the program or is this only possible when I go to Start --> Execute --> cmd --> cd c:\ ?

If this is the case, what do I enter after that, the full line: C:\Documents and Settings\Johan Berntzen\Mijn documenten\Solicitaties\Sol.Devlop ???


>in the example you use, filename can be any STL string object that is in scope.

Euh, do you mean by STL (Standard Template Library), and I know this might be a stupid question, but what does 'in scope' mean :o

Sorry to ask this probably simple questions for you all, I just want to try out this example to see what happens and try several things out, thing is, I can't get this bloody thing to work :confused:

JoBe 36 Posting Pro in Training

Additional question,

When I have this program, what additional info do I have to enter to let this program effectively output the desired solutions?

#include <fstream>
#include <iostream>
#include <string>

using namespace std;

int main()
{  
	string filename, s, longest = "";
	int maxlen = 0;

	cout<<"Name inputfile: ";

	getline(cin, filename, '\n');

	ifstream in(filename.c_str());

	if (in.fail())
	{
		cout<<"Can't open inputfile.\n";
		
		return 1;
	}

	while (getline(in, s, '\n'), !in.fail())
		if (s.length() > maxlen) 
		{
			longest = s;
			maxlen = s.length();
		}

	cout<<"Longest read ruel:\n";
	cout<< longest << endl;

	cout<<"Press any key to continue!\n";
	cin.get();

	return 0;
}

What is it that I have to enter into this part to let it work when I execute this program:

getline(cin, filename, '\n');

:?:

JoBe 36 Posting Pro in Training

Thanks for your example Stoned_coder. So, the correct way of dealing with something like this is to use polymorphism then, atleast, that's what I can make out of your example correct :?:

JoBe 36 Posting Pro in Training

Hmm, ok, think Ive got it.

Thanks for the help :!:

JoBe 36 Posting Pro in Training

Ok, but am I correct in assuming that where ("aa") is written, there could/should be a link like this in for example: C:/MyPrograms/Microsoft Visual/ ... ?

Also, if this is correct, is this piece of code

ifstream ff(...

just a variable of ifstream then?

JoBe 36 Posting Pro in Training

Thanks for the help winbatch,

So, if I understand you correctly and explaining it in my own words, the advantage of using self defined in- & output operator is that you can actually send data towards other programs, is that correct?