Thread: Need opinion...
View Single Post
Old Jan 21st, 2005, 5:03 AM   #27
Broax
Hobbyist Programmer
 
Broax's Avatar
 
Join Date: Jan 2005
Location: Porto, Portugal
Posts: 142
Rep Power: 4 Broax is on a distinguished road
Send a message via MSN to Broax
Yes, that was a really really stupid mistake by me, but I'm getting lots of errors that I don't understand... Like:

Line: 13 - syntax error before '{' token
Line: 15 - ISO C++ forbids declaration of ' var_total' with no type
Line: 17 - syntax error before '<<' token
Line: 18 - syntax error before '<<' token

Anyway, when I type <b>int something = 12</b> it works just fine, but if I try to declare the variable and assign a value to it in diferent lines I get the following error:

Line: 12 - redefenition of 'std::string var_myname'
Line: 08 - 'std::string var_myname' previously declared here

Wasn't it suppose to work anyway?

Anyway, the reason I wasn't able to reply yesterday, it 'cause I had to do some paperwork and some stuff, and now I'm a FireFighter!

I just need some time so the process gets through (here in portugal redtape is a huuuge problem) but I think that in, like... 2 weeks I'll start!

I can't wait!

EDIT: I managed to fix one of the errors, I seem to oversee basic strings and I missed a naughty semicolon on the <b>int main()</b> line... which takes care of error:

Line: 13 - syntax error before '{' token

I also removed the <b>int var_total</b> declaration for the same strange reason I removed the other declarations... I really don't get that, I thought that I was supposed to declare it be for definning it... Does anyone care to explain to me please?

EDIT: NEW AMAZING UPDATE:

I forgot how important the misterious <b><<</b> can be, so I just added a couple of these before the variable output and the code now acts like a charm!

Final code is:

/*Why oh why can't I handle a 
lot of variables!? I don't know
but I will sure try now... :D */

#include <iostream>
using namespace std;

string var_myname = "Joao Oliveira (aka broax)";
int var_num1 = 10;
int var_num2 = 9;

int main()
{
int var_total = var_num1 + var_num2;
    
    cout << "So let's try some more of this baisc programming stuff \n" << endl;
    cout << "My name is " << var_myname << "and I'm " << var_total << "years old." << endl;
    
    return 0;
}

Hurray for my amazing programming skills!!

Anyway, I'd still appreciate very much an explanation why I get an error everytime I try to declare and assign values to a string in two lines of code, as follows:

string pretty_little_variable;
pretty_little_variable = "I'll beat the shit out of bill gate's pu*** OS! :D";

If I want it to work I must do:
string pretty_little_variable = "I'll beat the shit out of bill gate's pu*** OS!:D";
instead!

Is this normal?
Should it happen?
Is it something that I miss-learned?
It seems to be connected to the <b>std</b> thing, so maybe it's just worked on the older <ioheaders.h> thing.

Thanks for the attention...
__________________
PORTUGALPORTUGA
PORTUGALPORTUGA
PORTUGALPORTUGA
PORTUGALPORTUGA
PORTUGALPORTUGA

Last edited by Broax; Jan 21st, 2005 at 5:41 AM.
Broax is offline   Reply With Quote