Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


[C++, Linux] Can't compile correct code


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 Taint   Members   -  Reputation: 132

Like
0Likes
Like

Posted 14 February 2014 - 12:11 PM

I'm using the g++ compiler and it can handle the basic stuff, but as soon as I try to use pointers it gives me errors. I 100% know the code is correct because I even pasted code from C++ Primer 5th Edition into it and it still isn't working. I did download a load of dev libraries when trying to install SFML so I'm thinking maybe that did it, but I don't know. I also don't have the slightest idea how to reverse it.

 

This is the code I pasted from C++ Primer 5th Edition, which apparently is the best book for learning. I've tried compiling it with g++ main.cpp -o main, and also with the -std=C++11 flag.

#include <iostream>
int main()
{
	using namespace std;
	int updates = 6;
// declare a variable
	int * p_updates;
// declare pointer to an int
	p_updates = &updates;
// assign address of int to pointer
// express values two ways
	cout << “Values: updates = “ << updates;
	cout << “, *p_updates = “ << *p_updates << endl;
// express address two ways
	cout << “Addresses: &updates = “ << &updates;
	cout << “, p_updates = “ << p_updates << endl;
// use pointer to change value
	*p_updates = *p_updates + 1;
	cout << “Now updates = “ << updates << endl;
	return 0;
}

Why does this happen every time I try and learn anything new in C++?



Sponsor:

#2 dejaime   Crossbones+   -  Reputation: 4119

Like
4Likes
Like

Posted 14 February 2014 - 12:17 PM

You should also post the error, so we could know what exactly went wrong.


Edited by dejaime, 14 February 2014 - 12:17 PM.


#3 Melkon   Members   -  Reputation: 532

Like
1Likes
Like

Posted 14 February 2014 - 12:19 PM

 I 100% know the code is correct

 

Well, i work as a c++ developer, and i am never brave enough to say that when i have a compile error. smile.png

 

At first look it seems fine for me but... please, write the compile error, because it's much more easier to help if we see what's your problem.


Edited by Melkon, 14 February 2014 - 12:23 PM.


#4 Taint   Members   -  Reputation: 132

Like
1Likes
Like

Posted 14 February 2014 - 12:24 PM

Sorry guys! This is the error:

 g++ main.cpp -o main
main.cpp:12:2: error: stray ‘\342’ in program
  cout << “Values: updates = “ << updates;
  ^
main.cpp:12:2: error: stray ‘\200’ in program
main.cpp:12:2: error: stray ‘\234’ in program
main.cpp:12:2: error: stray ‘\342’ in program
main.cpp:12:2: error: stray ‘\200’ in program
main.cpp:12:2: error: stray ‘\234’ in program
main.cpp:13:2: error: stray ‘\342’ in program
  cout << “, *p_updates = “ << *p_updates << endl;
  ^
main.cpp:13:2: error: stray ‘\200’ in program
main.cpp:13:2: error: stray ‘\234’ in program
main.cpp:13:2: error: stray ‘\342’ in program
main.cpp:13:2: error: stray ‘\200’ in program
main.cpp:13:2: error: stray ‘\234’ in program
main.cpp:15:2: error: stray ‘\342’ in program
  cout << “Addresses: &updates = “ << &updates;
  ^
main.cpp:15:2: error: stray ‘\200’ in program
main.cpp:15:2: error: stray ‘\234’ in program
main.cpp:15:2: error: stray ‘\342’ in program
main.cpp:15:2: error: stray ‘\200’ in program
main.cpp:15:2: error: stray ‘\234’ in program
main.cpp:16:2: error: stray ‘\342’ in program
  cout << “, p_updates = “ << p_updates << endl;
  ^
main.cpp:16:2: error: stray ‘\200’ in program
main.cpp:16:2: error: stray ‘\234’ in program
main.cpp:16:2: error: stray ‘\342’ in program
main.cpp:16:2: error: stray ‘\200’ in program
main.cpp:16:2: error: stray ‘\234’ in program
main.cpp:19:2: error: stray ‘\342’ in program
  cout << “Now updates = “ << updates << endl;
  ^
main.cpp:19:2: error: stray ‘\200’ in program
main.cpp:19:2: error: stray ‘\234’ in program
main.cpp:19:2: error: stray ‘\342’ in program
main.cpp:19:2: error: stray ‘\200’ in program
main.cpp:19:2: error: stray ‘\234’ in program
main.cpp: In function ‘int main()’:
main.cpp:12:19: error: found ‘:’ in nested-name-specifier, expected ‘::’
  cout << “Values: updates = “ << updates;
                   ^
main.cpp:12:13: error: ‘Values’ has not been declared
  cout << “Values: updates = “ << updates;
             ^
main.cpp:12:35: error: expected primary-expression before ‘<<’ token
  cout << “Values: updates = “ << updates;
                                   ^
main.cpp:13:13: error: expected primary-expression before ‘,’ token
  cout << “, *p_updates = “ << *p_updates << endl;
             ^
main.cpp:13:32: error: expected primary-expression before ‘<<’ token
  cout << “, *p_updates = “ << *p_updates << endl;
                                ^
main.cpp:15:13: error: ‘Addresses’ was not declared in this scope
  cout << “Addresses: &updates = “ << &updates;
             ^
main.cpp:15:22: error: expected ‘;’ before ‘:’ token
  cout << “Addresses: &updates = “ << &updates;
                      ^
main.cpp:16:13: error: expected primary-expression before ‘,’ token
  cout << “, p_updates = “ << p_updates << endl;
             ^
main.cpp:16:31: error: expected primary-expression before ‘<<’ token
  cout << “, p_updates = “ << p_updates << endl;
                               ^
main.cpp:19:13: error: ‘Now’ was not declared in this scope
  cout << “Now updates = “ << updates << endl;
             ^
main.cpp:19:17: error: expected ‘;’ before ‘updates’
  cout << “Now updates = “ << updates << endl;



#5 Brother Bob   Moderators   -  Reputation: 8630

Like
7Likes
Like

Posted 14 February 2014 - 12:28 PM

You're using the wrong quote marks. You're using “ while the correct mark is ".



#6 Lactose!   GDNet+   -  Reputation: 3835

Like
3Likes
Like

Posted 14 February 2014 - 12:28 PM

cout << “Values: updates = “ << updates;

That's using an incorrect symbol.

It should be ", not “

---

EDIT: Ninjaed by Brother Bob. Curses!


Edited by CoreLactose, 14 February 2014 - 12:29 PM.


#7 Melkon   Members   -  Reputation: 532

Like
0Likes
Like

Posted 14 February 2014 - 12:31 PM

Edit: Nvm, others answered it already.


Edited by Melkon, 14 February 2014 - 12:31 PM.


#8 Taint   Members   -  Reputation: 132

Like
0Likes
Like

Posted 14 February 2014 - 12:31 PM

Brilliant, thank you.



#9 BeerNutts   Crossbones+   -  Reputation: 3018

Like
1Likes
Like

Posted 14 February 2014 - 04:19 PM

A colleague was recently befuddled why a simple command line argument wasn't working.  He was passing in -n as an argument, copied straight from an email.

 

Well, it turned out, some email editor (Outlook) had changed the "-" to some longer single character - (possibly UNICODE) and it was screwing up the argument.

 

Lesson is, be careful when copying and pasting;  sometimes it doesn't give you exactly what you expect.


My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

#10 Serapth   Crossbones+   -  Reputation: 5792

Like
0Likes
Like

Posted 14 February 2014 - 04:54 PM

A colleague was recently befuddled why a simple command line argument wasn't working.  He was passing in -n as an argument, copied straight from an email.

 

Well, it turned out, some email editor (Outlook) had changed the "-" to some longer single character - (possibly UNICODE) and it was screwing up the argument.

 

Lesson is, be careful when copying and pasting;  sometimes it doesn't give you exactly what you expect.

 

 

I had a similar experience in my ancient history, pasting code from word.  MIcrosoft apparently have a "smart quote" character, and non-Visual Studio compilers really weren't happy with it.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS