Learning C++ Programming and I need some advice

Page 1 of 2 [ 20 posts ]  Go to page 1, 2  Next

Ark
Yellow-bellied Woodpecker
Yellow-bellied Woodpecker

User avatar

Joined: 13 May 2012
Age: 30
Gender: Male
Posts: 51

16 May 2012, 10:24 pm

I need a smart programmer who knows about C++ to help me out please:

I got this book called "Sams Teach Yourself C++ in 24 Hours" and I am attempting to write my first program as described in the book called "Motto".

I wrote the following program in a notepad file:

#include <iostream>

int main()
{
std::cout << "Solidum petit in profundis!\n";
return 0;
}

and then I saved it to my desktop, opened my command prompt and typed "g++ Motto.cpp -o Motto.exe" in order to compile and link the program but I always receive these error messages:

g++: error: Motto.cpp: No such file or directory
g++: fatal error: no input files
compilation terminated

I have MinGW installed. I have followed every detail of the book's instructions. I need a smart programmer who is familiar with c++ to help me out please. I await your clever solution, thank you.

~Ark



Last edited by Ark on 16 May 2012, 11:01 pm, edited 1 time in total.

CornerPuzzlePieces
Deinonychus
Deinonychus

User avatar

Joined: 27 Feb 2012
Gender: Male
Posts: 308
Location: B.C Canada

16 May 2012, 10:38 pm

I'm just a beginner so I might not be too much help...

But that -cout- command shouldn't have -std:- in front should it?

**Edit:

If it is, the code i see online has "std::cout" do you are missing a ":"



Ark
Yellow-bellied Woodpecker
Yellow-bellied Woodpecker

User avatar

Joined: 13 May 2012
Age: 30
Gender: Male
Posts: 51

16 May 2012, 11:00 pm

CornerPuzzlePieces wrote:
I'm just a beginner so I might not be too much help...

But that -cout- command shouldn't have -std:- in front should it?

**Edit:

If it is, the code i see online has "std::cout" do you are missing a ":"


You are correct however my document does have the additional ":" in it, I just misplaced it in this particular document. Very good eye you have however I am still suffering from the same problem, if you have any other solutions please let me know and thank you for attempting to help me thus far.

~Ark



CornerPuzzlePieces
Deinonychus
Deinonychus

User avatar

Joined: 27 Feb 2012
Gender: Male
Posts: 308
Location: B.C Canada

16 May 2012, 11:19 pm

Hmm, on second thought those errors look specific to whatever the book is using for a compiler.. When I did my class it was with this: http://download.cnet.com/Dev-C/3000-2069_4-12686.html

The programming is all the same, maybe try your code on a different compiler? Dev CPP was simple, you might prefer it instead?



Ark
Yellow-bellied Woodpecker
Yellow-bellied Woodpecker

User avatar

Joined: 13 May 2012
Age: 30
Gender: Male
Posts: 51

16 May 2012, 11:31 pm

CornerPuzzlePieces wrote:
Hmm, on second thought those errors look specific to whatever the book is using for a compiler.. When I did my class it was with this: http://download.cnet.com/Dev-C/3000-2069_4-12686.html

The programming is all the same, maybe try your code on a different compiler? Dev CPP was simple, you might prefer it instead?


If I use Dev C++ like you suggested would I still be able to complete the projects in this book? I still want to use this book as my learning guide. The book itself also came with Code::blocks but I tried using codeblocks and you have to write the program differently than described in the book so I uninstalled it.



cyberscan
Veteran
Veteran

User avatar

Joined: 16 Apr 2008
Age: 57
Gender: Male
Posts: 1,296
Location: Near Panama, City Florida

16 May 2012, 11:45 pm

Try typing the full path to Motto.cpp

Ex: g++ C:\myprogramcode\mysubdirectory\Motto.cpp


_________________
I am AUTISTIC - Always Unique, Totally Interesting, Straight Talking, Intelligently Conversational.
I am also the author of "Tech Tactics Money Saving Secrets" and "Tech Tactics Publishing and Production Secrets."


LookTwice
Velociraptor
Velociraptor

User avatar

Joined: 30 Oct 2011
Age: 113
Gender: Male
Posts: 441
Location: Lost, somewhere

16 May 2012, 11:45 pm

cd Desktop

... ?



CornerPuzzlePieces
Deinonychus
Deinonychus

User avatar

Joined: 27 Feb 2012
Gender: Male
Posts: 308
Location: B.C Canada

17 May 2012, 12:06 am

Ark wrote:
CornerPuzzlePieces wrote:
Hmm, on second thought those errors look specific to whatever the book is using for a compiler.. When I did my class it was with this: http://download.cnet.com/Dev-C/3000-2069_4-12686.html

The programming is all the same, maybe try your code on a different compiler? Dev CPP was simple, you might prefer it instead?


If I use Dev C++ like you suggested would I still be able to complete the projects in this book? I still want to use this book as my learning guide. The book itself also came with Code::blocks but I tried using codeblocks and you have to write the program differently than described in the book so I uninstalled it.


I think so.. C++ is pretty versatile, try typing the full path like cyberscan mentioned and make sure any software is in the cd tray..

But for me, a simple compiler is key for someone who is just learning..



Ark
Yellow-bellied Woodpecker
Yellow-bellied Woodpecker

User avatar

Joined: 13 May 2012
Age: 30
Gender: Male
Posts: 51

17 May 2012, 12:55 am

CornerPuzzlePieces wrote:
Ark wrote:
CornerPuzzlePieces wrote:
Hmm, on second thought those errors look specific to whatever the book is using for a compiler.. When I did my class it was with this: http://download.cnet.com/Dev-C/3000-2069_4-12686.html

The programming is all the same, maybe try your code on a different compiler? Dev CPP was simple, you might prefer it instead?


If I use Dev C++ like you suggested would I still be able to complete the projects in this book? I still want to use this book as my learning guide. The book itself also came with Code::blocks but I tried using codeblocks and you have to write the program differently than described in the book so I uninstalled it.


I think so.. C++ is pretty versatile, try typing the full path like cyberscan mentioned and make sure any software is in the cd tray..

But for me, a simple compiler is key for someone who is just learning..


Okay I like the idea of typing the exact path to the Motto.cpp but what exactly would the full path be? When he said "myprogramcode" do I put c++ or? Sorry, I am extremely new at this.



cyberscan
Veteran
Veteran

User avatar

Joined: 16 Apr 2008
Age: 57
Gender: Male
Posts: 1,296
Location: Near Panama, City Florida

17 May 2012, 1:08 am

I don't know where this file is located on your computer. You can try to use the search function within Windows to find the full path.


_________________
I am AUTISTIC - Always Unique, Totally Interesting, Straight Talking, Intelligently Conversational.
I am also the author of "Tech Tactics Money Saving Secrets" and "Tech Tactics Publishing and Production Secrets."


zxy3cpn
Veteran
Veteran

User avatar

Joined: 7 May 2012
Age: 40
Gender: Male
Posts: 934
Location: London, UK

17 May 2012, 6:06 am

Rather than passing the full path to g++ once you find it, it's probably easier to just change to that directory and run g++ from there. That way, you'll keep the executable and the source in the same directory. For example, if Windows tells you that Motto.cpp is in C:\Users\me, just do "cd C:\Users\me" first and then run g++ as you did before.


_________________
If my username is annoying to type, shorten it (e.g. z3n)!


Ark
Yellow-bellied Woodpecker
Yellow-bellied Woodpecker

User avatar

Joined: 13 May 2012
Age: 30
Gender: Male
Posts: 51

17 May 2012, 9:12 am

zxy3cpn wrote:
Rather than passing the full path to g++ once you find it, it's probably easier to just change to that directory and run g++ from there. That way, you'll keep the executable and the source in the same directory. For example, if Windows tells you that Motto.cpp is in C:\Users\me, just do "cd C:\Users\me" first and then run g++ as you did before.


I just did exactly that but I still get the error message for some reason. It keep saying "no such file or directory". I wrote the program on NotePad, could the problem be that I am using a bad text editor that the prompt if failing to recognize? Should I use a different text editor?



marshall
Veteran
Veteran

User avatar

Joined: 14 Apr 2007
Gender: Male
Posts: 10,752
Location: Turkey

17 May 2012, 10:38 am

Ark wrote:
zxy3cpn wrote:
Rather than passing the full path to g++ once you find it, it's probably easier to just change to that directory and run g++ from there. That way, you'll keep the executable and the source in the same directory. For example, if Windows tells you that Motto.cpp is in C:\Users\me, just do "cd C:\Users\me" first and then run g++ as you did before.


I just did exactly that but I still get the error message for some reason. It keep saying "no such file or directory". I wrote the program on NotePad, could the problem be that I am using a bad text editor that the prompt if failing to recognize? Should I use a different text editor?

There's no problem with the file itself or the text editor. I'm pretty certain of that.

The issue is you need to find out what the default path the compiler you installed looks for source code in is. You should be able to find this out if there's a readme.txt or other documentation in the directory where you installed the compiler. Once you figure this out you can make a "Motto" subdirectory inside the default path directory and put Motto.cpp inside it. Then just type the subdirectory name when you run g++ and it should automatically find and compile all the .cpp files inside.



MyFutureSelfnMe
Veteran
Veteran

User avatar

Joined: 26 Feb 2010
Age: 45
Gender: Male
Posts: 1,385

17 May 2012, 10:52 am

If you don't understand paths and filenames, I'd suggest learning more before moving on to C++.



zxy3cpn
Veteran
Veteran

User avatar

Joined: 7 May 2012
Age: 40
Gender: Male
Posts: 934
Location: London, UK

17 May 2012, 12:09 pm

This is difficult to diagnose without being at the machine. Let's have another go:

1. Can you obtain the path to the file? You may be able to get it by right-clicking on it and going to "Properties" (my Windows knowledge is a bit rusty). Post it here.

2. From which directory are you running g++? If it's not the same as you found in 1. above, change use cd to change.

3. Check the contents of your current directory using dir. Is your source file listed?

Post what you see in those steps and it should be easier to help you.


_________________
If my username is annoying to type, shorten it (e.g. z3n)!


CornerPuzzlePieces
Deinonychus
Deinonychus

User avatar

Joined: 27 Feb 2012
Gender: Male
Posts: 308
Location: B.C Canada

17 May 2012, 2:14 pm

See, this is interfering with your learning.

Try Dev CPP, you will like it much more! Promise! :)