very cherry quick question

Hey guys! sup@ quick question.

why if i run this without the int _tmain (int argc.....) etc it wont work? secondly i have to put like 4 or 5 cin.get() at the end so that whenever i input the number and something comes out, it doesnt automatically disappear. is there anyway of changing it or something so i dont have to put a cin.get() for like every cout or cin i have?

THX A LOT MY BROTHERS AND SISTERS



// taco_2.cpp : this one just uses basic user input to give a computer output. 
//

#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])
{
	return 0;
}


// initialization of variables

#include <iostream>
using namespace std;

int main ()
{

	int paulnum1;
	int paulnum2;
	
cout << " How many you want " << endl;
cin >> paulnum1;
cout << " ur new number is " << endl; 
paulnum1 = paulnum1 + 20;
cout << paulnum1 << endl;

cout << " now pick another number " << endl;
cin >> paulnum2;
cout << " ur new number is " << endl; 
paulnum2 = paulnum1 + 20;
cout << paulnum2 << endl;
cout << " there u have ur new number on top u bitch " << endl;

  cin.get();
  cin.get();
  cin.get();
  cin.get();
  return 0;
}
Last edited on
why if i run this without the int _tmain (int argc.....) etc it wont work?

This is particular to your installation of MSVS, you may have better luck asking this on their form but it looks like something is looking to execute "int _tmain(...)" before entering "int main()". Chances are you have to tick off a check box in setting some where but this isn't my choice IDE so I don't know which one it would be.

secondly i have to put like 4 or 5 cin.get() at the end

This is because something is stuck in your buffer. "cin.get()" only removes one character from the input buffer at a time, you are better off using "cin.ignore(....)": http://www.cplusplus.com/reference/iostream/istream/ignore/
ah yes thank you my friend! whenever i make a new win 32 console for writing code i check this button but i am unaware what it does!
edit: i think its because i always check this: Create directory for solution

i will also check out that link you posted!

Last edited on
It's because of the kind of project you opened, you need to create a New Project and select Empty Project.

I worked with MSVS 10 for a while and i believe the _tmain is required for CLI/C++, I don't remember the technical reason other than that the compiler calls that function and determines which function you really want. Makes no sense to me, but it's Microsoft, I don't ask them questions.
haha funny point you have made there! i see what you mean.
Oh however, whenever I make empty projects they do appear, however they do not give me the box to write by code in! do you know what i mean? haha
Yes I do know what you mean. If the project manager isn't open, you can open it by going to View->Project Manager. From the Project Manager, you should already have a blank .cpp file, usually called main.cpp. If for whatever reason it creates the project with no files in it, you can always add a new file. File -> New... -> Empty File.

Sorry if it's not 100% correct, I don't use MSVS as I can't stand it, the error messages are horrible, they force you to do everything Microsoft's way, and it's just a pain to deal with. Hope that helps.
thanks!! you guys have really helped me. do you mind if i ask you what is your alternative to MSVS?
I personally, along with a few other people on this site use Code::Blocks with the MingW Compiler. The IDE is smooth, quick, and doesn't have nonsense you don't need. The only issue is that it hasn't been updated for some time now, but still works exceptionally. Others don't use an IDE and just compile directly from the command line which is actually very efficient, but I prefer an all in one IDE.
the error messages are horrible


I don't find them any worse than anything else, honestly.

they force you to do everything Microsoft's way


Could you give an example?
From thread http://cplusplus.com/forum/beginner/72597/
VS Compiler wrote:
1>------ Build started: Project: assignment 4 again, Configuration: Debug Win32 ------
1> assignment 4 again.cpp
1>c:\users\abbey\documents\visual studio 2010\projects\assignment 4 again\assignment 4 again\assignment 4 again.cpp(10): error C2062: type 'int' unexpected
1>c:\users\abbey\documents\visual studio 2010\projects\assignment 4 again\assignment 4 again\assignment 4 again.cpp(12): error C2065: 'stop' : undeclared identifier
1>c:\users\abbey\documents\visual studio 2010\projects\assignment 4 again\assignment 4 again\assignment 4 again.cpp(12): fatal error C1903: unable to recover from previous error(s); stopping compilation
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


It only shows two errors, while Code Blocks showed me about 15 errors. And I didn't mean horrible as in undescriptive, I think there is a lot of compilers that have issues telling you whats wrong sometimes.

And forcing you to do everything Microsoft's way was referring to the that if you don't know exactly what you're doing, like in srikev100's instance, it can greatly confuse someone. I even had a C++ book that tried teaching using the MSVS 10 IDE and I just got fed up with it. Most of their projects you can create are geared only towards Microsoft's OS's. To each their own, but I'm content with a decent text editor, code completion and syntaxing with a linker/compiler.

I've found that CBs compiler errors are much smarter than MSVS's as it gives you warnings and hints, specificies the function and possible solutions. I also feel that CB runs much faster than MSVS and the compiler is quicker as well, I use GCC.
It only shows two errors, while Code Blocks showed me about 15 errors.


Number of errors output is probably not the best way to determine a good compiler...but what are the errors that Code blocks gives you?

I don't see any huge errors other than those two right off the bat.

And forcing you to do everything Microsoft's way was referring to the that if you don't know exactly what you're doing, like in srikev100's instance, it can greatly confuse someone.


I suppose you do have a point there.
Code Blocks Compiler wrote:
C:\...\Test Project\main.cpp||In function 'void Read(int*, int*, int*, int*)':|
C:\...\Test Project\main.cpp|10|error: expected unqualified-id before 'int'|
C:\...\Test Project\main.cpp|12|error: 'stop' was not declared in this scope|
C:\...\Test Project\main.cpp|29|error: 'Ai' was not declared in this scope|
C:\...\Test Project\main.cpp||In function 'void print(int*, int, int, char*)':|
C:\...\Test Project\main.cpp|118|error: declaration of 'int nofcorrectanswers' shadows a parameter|
C:\...\Test Project\main.cpp|138|error: '::main' must return 'int'|
C:\...\Test Project\main.cpp||In function 'int main()':|
C:\...\Test Project\main.cpp|147|error: 'system' was not declared in this scope|
||=== Build finished: 6 errors, 0 warnings ===|


Sorry, it only gave me six.
Well, the first three are probably due to the differences in how the compiler tries to deal with missing ';', errors, etc.

Do you have treat warnings as errors? AFAIK shadowing a parameter isn't an error in C or C++.

main needing to return an int is a good one though, VC++ probably still uses a C backend that doesn't care or something.

System is probably due to what iostream is including so it's implementation dependent.

So really the only other thing it caught that was an error was int main (although from what I hear there are plenty of compilers that let that through for some reason).
As far as I know, this is the first compiler I've ever used that didn't allow void main(), which I was taught using.

As for the shadowing params, I believe a lot of compilers throw warnings, but I believe it's supposed to be an error, I have no information to support that though.

As for the system part, it was because the system("pause"); at the end of the main, which is actually supposed to be caught.
Edit: The #include<stdlib.h> was never used.

If you look at the VS compiler, the compiler stopped searching for errors once it couldn't find stop, which IMHO, that is a horrible way to handle compile errors. It should search the entire program for all errors before stopping, not receiving a fatal error over a variable. But then again, it does exactly as it was meant to, read line by line until it is unable to read the next line.

Edit: That code in general is just bad, it needs rewritten altogether.
Last edited on
As for the system part, it was because the system("pause"); at the end of the main, which is actually supposed to be caught.
Edit: The #include<stdlib.h> was never used.


What I mean is that iostream on VC++ could theoretically include stdlib at some point if it needed to, the standard doesn't care. It's still good practice to include all your headers because of stuff like that though.

It should search the entire program for all errors before stopping, not receiving a fatal error over a variable.


Well the problem is that you can't continue sometimes:

std::cout<<x;

You can't know whether this is valid or not without knowing the type of x. If x is a class, you can't even use normal operators if the user hasn't defined them.
And I completely agree with that logic, but how does a GNU compiler do more than a big budget company's compiler can do? That's out of context, but you know what I mean, how does GCC scan the entire file, while MSVS compiler stops as soon as one variable isn't declared?
Topic archived. No new replies allowed.