Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Begginer needs help with VC++ 6

Status
Not open for further replies.

Mrafcho001

Technical User
Jan 18, 2005
7
US
I know Visual C++ 6 is quite old, but i got it from a friend

untill now i was using Dev-C++.

For some reason VC++ wont compile anything i would get an error mesage that says:
No compile tool is associated with the file extension.

it also says it's an .txt file instead of bein .cpp

Thanks.
 
How did you create the file?? Did you start with File->New... Text File? If so, then you should choose C++ Source file instead.

Did you create the file in Notepad and save it before opening it in Visual C++? If so, then sometimes Notepad adds on a .txt to the filename if you don't turn off the proper option in the Windows Explorer.

If it's neither of those, then maybe you want to give more information. The file should have a .cpp extension if you want to compile it as C++ code.
 
ok, i got it working thanks


i have another question..

it keeps creating this "weird" files for example:
.pdb .ilk .opt .aps .pch .obj and .idb files..

what are they and are they necessary?

Thanks again
 
oo and i forgot to add..
is there a way to compile a .cpp file without having to make a new project for it. sorry i forgot to post it in the post above.
 
You can compile using the command line without creating a project, but I don't see why it would be necessary, it's not that hard to create a new blank project.

The "weird: files are used by the compiler. If you delete them, everything should still work (based on what I know of the file extensions you listed). However, there is no reason to delete these files since they will just be generated again. I'd only suggest deleteing those files when you are giving your code to someone else... Generally, all you need is the .h, .cpp files, and the .dsp and .dsw if you want to include the Visual Studio project and workspace settings.
 
See also File Types Created for Visual C++ Projects article in MSDN.
 
Try this procedure (I have checked it on W2K):
1. In Explorer select any cpp file then right click and select Properties.
2. Press Change button on Open with line
3. Select Microsoft (R) Developer Studio and set Always use this program... on.
4. OK, OK, OK..
Now VC++ can process cpp files (with default project settings).

There is an article in MSDN how to correct Registry for using file extensions in VS IDE. It's rather complicated procedure...

Obviously, VS installation process was incompleted on you PC if no association between VS IDE and cpp files...

May be it's better to add cpp files in a new (empty) VC++ project by hand...
 
ok thanks guys but it seems there is a bigger problem

when i compile something with VC++6 it only runs properly on my computer, when i send it to someone else they say it just closes after you input the value

why is that, and how can i fix it?
 
This is most likely due to a common problem with beginner programs. When you double-click on the exe file, it creates a new console window, executes the program, and closes the window when the program completes. On your machine, you are probably running it from Visual C++, which adds on special code so that the window stays open until you close it.

There are several solutions. One solution is to have the other person open up a command prompt (e.g. Start->Run... cmd.exe) and navigate to the location of the exe file you sent using the 'cd' command. Then when the user executes the program by typing its name at the prompt, the prompt window stays open after the program finishes.

Another solution is to add a pause to your program code. How you do this depends on whether you want your C++ code to be portable, as well as other code in your program. One simple C++ way is to add the following two lines of code to the end of your main function (you also have to #include <limits>:
Code:
std::cin.ignore(std::numeric_limts<std::streamsize>::max(), '\n');
std::cin.get();
That code just ignores any leftover data in the input stream and waits for the user to press Enter before exiting the program.

Another common one is that isn't always portable is:
Code:
system("pause");
Make sure you #include <cstdlib> or <stdlib.h> for that.
 
i tried both ways.
the first way i kept getting a compiling error.

2nd way it was really weird!
this is what i mean:
Untitled-2.gif


as you see everything goes normal untill i enter the C°, then it just says press anything to continue, which isn't suppose to happen. then i press enter and the answer comes up..

weird huh?
any other ways to fix this
 
You might want to post your code so we can see what the problem is.
 
when i compile it with dev-c++ it works just fine but when i compile it with VC++6 its all weird

the code:
Code:
#include <iostream.h>
#include <stdlib.h>


double cf(double c)
{
	if(c == 0)
	{
		double f1 = 32;

		return f1;
	}
	if(c == 100)
	{
		double f2 = 212;

		return f2;
	}
	if(c != 0 && c != 100)
	{
		double a, b;

		a = c * (9/5);
		b = a + 32;

		return b;
	}
	return 0;
}
double fc(double f)
{
	if(f == 32)
	{
		double c1 = 0;

		return c1;
	}
	if(f == 212)
	{
		double c2 = 100;

		return c2;
	}
	if(f != 32 && f != 212)
	{
		double x, z;

		x = f - 32;
		z = x * (5/9);
		
		return z;
	}
	return 0;
}

int main()
{
	
	int choice;
    double c, f;
	
	cout << "What type of conversion would you like?";
	cout << "\n1. C to F" << endl;
	cout << "2. F to C" << endl;
	cin >> choice;

	if(choice == 1)
	{
		
		cout << "Please Enter C" << char(248);
		cin >> c;
		f = cf(c);
		cout << c << char(248) << "C = " << f << char(248) << "F\n";
	}
	if(choice == 2)
	{
		cout << "Plase Enter F"<< char(248);
		cin >> f;
		c = fc(f);
        cout <<  f << char(248) << "F = " << c << char(248) << "C\n";

	}
    if(choice != 1 && choice != 2)
	{
		cout << "Please Try again";
	}
	system("pause");
	return 0;

}
 
Simple problem...

You aren't explicitly flushing the text to the output stream. When you send your result to cout, it doesn't get sent to the console window until it is flushed. VC++6 doesn't flush it automatically either until the program finishes. So the system("pause") function is called before the results are printed. Then the results are printed after you hit a key to continue.

To solve this, you just need to explicitly flush the output. The simple way to do this is using endl, which adds a newline and flushes the output. Change your output line to:
Code:
cout << c << char(248) << "C = " << f << char(248) << "F"[red] << endl[/red];
Do the same for the other output line. All should be well after that.


By the way, the reason my first suggestion (ignore() and get()) didn't work is because your code non-standard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top