Me learning C++ aka "Can't get tabulator to work" resolved

This forum is for anything that doesn't specifically have to do with Better Than Wolves
Post Reply
User avatar
Mac
Posts: 251
Joined: Thu Sep 29, 2011 7:18 pm
Location: Northwest Germany

Me learning C++ aka "Can't get tabulator to work" resolved

Post by Mac »

First of:
I'm still a total newb in terms of programming

Started to learn C++ from a book recently and I've got the following question.

Even though \t(don't know proper description jet) is correct (did check other sources via google search)
it does not seem to do what it should do.

Code I am supposed to use is as follows
Spoiler
Show

Code: Select all

1: // Listing 2.2 zeigt die Verwendung von cout
 2: #include <iostream.h>
 3: int main()
 4: {
 5:     cout << "Hallo dort.\n";
 6:     cout << "Hier ist 5: " << 5 << "\n";
 7:     cout << "Der Manipulator endl beginnt eine neue Zeile.";
 8:     cout <<
 9:            endl;
10:     cout << "Hier ist eine große Zahl:\t" << 70000 << endl;
11:     cout << "Hier ist die Summe von 8 und 5:\t" << 8+5 << endl;
12:     cout << "Hier ist ein Bruch:\t\t" << (float) 5/8 << endl;
13:     cout << "Und eine riesengroße Zahl:\t";
14:     cout << (double) 7000 * 7000 <<
15:            endl;
16:     cout << "Vergessen Sie nicht, Jesse Liberty durch Ihren Namen"
                " zu ersetzen...\n";
17:     cout << "Jesse Liberty ist ein C++-Programmierer!\n";
18:     return 0;
19:     }
The Version I have typed out in Visual C++ 2010 Express matches this exactly.
After compiling and running it on my end the tabulator doesn't seem to work.

My hope is that someone who knows more than me can point me to possible errors I've made
Pm would also be fine if answering it within this thread could spawn unwanted discussion.

My Typed out version for comparison
Spoiler
Show

Code: Select all

# include <iostream>
using namespace std;
int main()
{
	cout << "Hallo dort\n";
	cout << "Hier ist die 5: " << 5 << "\n";
	cout << "Der Manipulator endl beginnt eine neue Zeile.";
	cout <<
		   endl;
	cout << "Hier ist eine grosse Zahl:\t" << 70000 << endl;
	cout << "Hier ist die Summe von 8 und 5:\t" << 8+5 << endl;
	cout << "Hier ist ein Bruch:\t\t" << (float) 5/8 << endl;
	cout << "Und hier eine riesengrosse Zahl:\t";
	cout << (double) 7000 * 7000 <<
		   endl;
	cout << "Vergessen sie nicht, Jesse Liberty durch ihren Namen"
		    " zu ersetzen...\n";
	cout << "Jesse Liberty ist ein C++-Programmierer!\n";
	return 0;
}
Last edited by Mac on Fri Sep 21, 2012 3:21 am, edited 1 time in total.
My Youtube channel.

Image
User avatar
Skyte Aero
Posts: 26
Joined: Sat Sep 10, 2011 11:58 pm

Re: Me learning C++ aka "Can't get tabulator to work"

Post by Skyte Aero »

Line 16, need to put that operator between Strings.

16: cout << "Vergessen Sie nicht, Jesse Liberty durch Ihren Namen"
<< " zu ersetzen...\n";
User avatar
MrLemon
Posts: 59
Joined: Fri Jul 20, 2012 7:05 pm

Re: Me learning C++ aka "Can't get tabulator to work"

Post by MrLemon »

Your Eszett may be causing problems too, It's character may not be supported.
User avatar
Mac
Posts: 251
Joined: Thu Sep 29, 2011 7:18 pm
Location: Northwest Germany

Re: Me learning C++ aka "Can't get tabulator to work"

Post by Mac »

MrLemon wrote:Your Eszett may be causing problems too, It's character may not be supported.
Thats in the code I'm supposed to use, the source I have typed does not have that character.
Skyte Aero wrote:Line 16, need to put that operator between Strings.

16: cout << "Vergessen Sie nicht, Jesse Liberty durch Ihren Namen"
<< " zu ersetzen...\n";
Will keep that in the back of my head for now, I'm not yet far enough to tell if thats true or not.
But the advice is nonetheless appreciated.
My Youtube channel.

Image
User avatar
Mac
Posts: 251
Joined: Thu Sep 29, 2011 7:18 pm
Location: Northwest Germany

Re: Me learning C++ aka "Can't get tabulator to work" reso

Post by Mac »

After fiddling a bit with it I resolved my issues.

Originally my thought was that the tab was somehow automatic,
turns i was wrong about that.
Big "D'oh" number 1

It works manually like the tab key in programs like word,
so adding or removing "\t" is key to getting it to look right.
Big "D'oh" number 2

Lastly some personal notice:
Somehow I've got the feeling that those who know programming must have had a good laugh
at such a beginner's mistake.
Could kinda understand it, feels justified/righteous on my part.

Anyhow,
I consider this topic done/resolved
My Youtube channel.

Image
User avatar
thekyz
Posts: 266
Joined: Wed Jul 20, 2011 5:52 am
Location: Rennes, France

Re: Me learning C++ aka "Can't get tabulator to work" reso

Post by thekyz »

Just for reference, though I don't really like to do that, you can totally type :

Code: Select all

cout << "bit" "bit""bit"
"bit"
"bit";
This is valid in c++ (in c as well for the string part, not the cout & << part of course ...).
It can be very useful in macros.
User avatar
Skyte Aero
Posts: 26
Joined: Sat Sep 10, 2011 11:58 pm

Re: Me learning C++ aka "Can't get tabulator to work" reso

Post by Skyte Aero »

thekyz wrote:Just for reference, though I don't really like to do that, you can totally type :

Code: Select all

cout << "bit" "bit""bit"
"bit"
"bit";
This is valid in c++ (in c as well for the string part, not the cout & << part of course ...).
It can be very useful in macros.
Don't you still need a + between Strings? Or I'm probably confusing this with Java now. Been too long since I touched a computer in this way...
User avatar
Mac
Posts: 251
Joined: Thu Sep 29, 2011 7:18 pm
Location: Northwest Germany

Re: Me learning C++ aka "Can't get tabulator to work" reso

Post by Mac »

I would like to request a lock on this tread.

Sorry guys, but for me this this topic is done and should be locked to
avoid unnecessary conflict.
My Youtube channel.

Image
Post Reply