Author |
Message |
Andy
|
Posted: Thu Feb 24, 2005 10:11 pm Post subject: Microsoft Visual Studio .Net 2003 |
|
|
hmm i recently acquired a copy of vsn2003 and i was very confused by the ide... i've been a vc6 user for quite some time.. i was just wondering if anyone knew what #include "stdafx.h" is for.. it seems that if i dont have that my programs in console app wont work... |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
wtd
|
Posted: Thu Feb 24, 2005 10:34 pm Post subject: (No subject) |
|
|
Show me your code. Anything console based should be easily possible in standard C++. |
|
|
|
|
![](images/spacer.gif) |
Andy
|
Posted: Thu Feb 24, 2005 10:36 pm Post subject: (No subject) |
|
|
i was simply doing some vector stuff
c++: |
// vector_push_back.cpp
// compile with: /EHsc
#include "stdafx.h"
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main( )
{
vector <int> v1,v2;
v2.push_back(6);
v2.push_back(7);
v1.push_back(1);
v1.push_back(3);
v1.push_back(2);
v1.push_back( 0);
v1.push_back(5);
v1.push_back(4);
v1.insert(v1.begin(),v2.begin(),v2.end());
//sort(v1.begin(),v1.end());
v1.erase(v1.begin()+3,v1.begin()+4);
for (int i=0;i<v1.size();i++)
cout<<v1[i];
}
|
and when i took off the #include "stdafx.h", it wont compile and gives me an error saying code: | c:\Documents and Settings\Owner.SUN\My Documents\Visual Studio Projects\ccc practice\ccc practice.cpp(29) : fatal error C1010: unexpected end of file while looking for precompiled header directive
|
|
|
|
|
|
![](images/spacer.gif) |
wtd
|
Posted: Thu Feb 24, 2005 10:41 pm Post subject: (No subject) |
|
|
Works fine with GCC, so I call bull$@!# on Microsoft's part. |
|
|
|
|
![](images/spacer.gif) |
Mazer
![](http://compsci.ca/v3/uploads/user_avatars/1323750815476d9f446d80c.png)
|
Posted: Fri Feb 25, 2005 8:32 am Post subject: (No subject) |
|
|
Could it be the project settings? I noticed that when some people create a new project it would add a bunch of crap to their main cpp file if they used a certain option. Maybe if you just choose an empty win32 console application? |
|
|
|
|
![](images/spacer.gif) |
bugzpodder
![](http://www.vbforums.com/avatar.php?userid=31755&dateline=1038631511)
|
Posted: Fri Feb 25, 2005 1:10 pm Post subject: (No subject) |
|
|
Andy wrote: i was simply doing some vector stuff
c++: |
// vector_push_back.cpp
// compile with: /EHsc
#include "stdafx.h"
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main( )
{
vector <int> v1,v2;
v2.push_back(6);
v2.push_back(7);
v1.push_back(1);
v1.push_back(3);
v1.push_back(2);
v1.push_back( 0);
v1.push_back(5);
v1.push_back(4);
v1.insert(v1.begin(),v2.begin(),v2.end());
//sort(v1.begin(),v1.end());
v1.erase(v1.begin()+3,v1.begin()+4);
for (int i=0;i<v1.size();i++)
cout<<v1[i];
}
|
and when i took off the #include "stdafx.h", it wont compile and gives me an error saying code: | c:\Documents and Settings\Owner.SUN\My Documents\Visual Studio Projects\ccc practice\ccc practice.cpp(29) : fatal error C1010: unexpected end of file while looking for precompiled header directive
|
what i would do is open a fresh C++ file (dont open any projects) - ie a file with .cpp extension. and paste your code in there and build/compile. try to take out the stdafx.h while doing that. also, instead of declaring int i=0 in the for loop, maybe take it out will help. attach a return 0; in the end. |
|
|
|
|
![](images/spacer.gif) |
wtd
|
Posted: Fri Feb 25, 2005 3:48 pm Post subject: (No subject) |
|
|
bugzpodder wrote: also, instead of declaring int i=0 in the for loop, maybe take it out will help. attach a return 0; in the end.
The declaration of i in the loop is fine, though you should use iterators. And yes, you do need to return 0, but it will work without that, and that isn't what the error in this case is about.
With iterator:
code: | for (vector<int>::iterator i(v1.begin()); i != i.end(); i++)
cout << *i; |
Or use for_each.
code: | #include <algorithm>
...
void print_int(int i) { cout << i; }
...
for_each(v1.begin(), v1.end(), print_int); |
|
|
|
|
|
![](images/spacer.gif) |
wtd
|
Posted: Fri Feb 25, 2005 6:35 pm Post subject: (No subject) |
|
|
Or more flexibly...
code: | #include <algorithm>
...
class print
{
private:
ostream& out;
public:
print(ostream& init_out) : out(init_out) {}
void operator()(int i) { out << i; }
};
...
for_each(v1.begin(), v1.end(), print(cout)); |
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Andy
|
Posted: Fri Feb 25, 2005 10:10 pm Post subject: (No subject) |
|
|
wow wtd! thx! question tho... for the sort function under the algorithm class... how can i make it sort from greatest to least? does it have something to do with the overloaded third parameter? |
|
|
|
|
![](images/spacer.gif) |
wtd
|
Posted: Fri Feb 25, 2005 10:40 pm Post subject: (No subject) |
|
|
Yes. The third argument is a binary predicate. This is either a function or function object which takes two arguments and returns a boolean value. For an ascending sort, the comparison is less than. To reverse it, we simply use greater than. So, we need a binary predicate:
code: | template <typename T>
bool desc(T a, T b)
{
return a > b;
} |
And then to sort:
code: | sort(v1.begin(), v1.end(), desc<int>); |
|
|
|
|
|
![](images/spacer.gif) |
Andy
|
Posted: Sat Feb 26, 2005 1:32 pm Post subject: (No subject) |
|
|
bugzpodder wrote:
what i would do is open a fresh C++ file (dont open any projects) - ie a file with .cpp extension. and paste your code in there and build/compile. try to take out the stdafx.h while doing that. also, instead of declaring int i=0 in the for loop, maybe take it out will help. attach a return 0; in the end.
i tried that... simply opening up vc7 and select new file, then c++ source, but when i press ctrl f5, nothing happens... |
|
|
|
|
![](images/spacer.gif) |
Andy
|
Posted: Sat Feb 26, 2005 2:42 pm Post subject: (No subject) |
|
|
wtd wrote:
code: | for (vector<int>::iterator i(v1.begin()); i != i.end(); i++)
cout << *i; |
dont u mean v1.end()? |
|
|
|
|
![](images/spacer.gif) |
wtd
|
Posted: Sat Feb 26, 2005 2:53 pm Post subject: (No subject) |
|
|
Andy wrote: wtd wrote:
code: | for (vector<int>::iterator i(v1.begin()); i != i.end(); i++)
cout << *i; |
dont u mean v1.end()?
Err... yes. |
|
|
|
|
![](images/spacer.gif) |
md
![](http://compsci.ca/v3/uploads/user_avatars/1849317514ed6c4399768d.png)
|
Posted: Sat Feb 26, 2005 6:56 pm Post subject: (No subject) |
|
|
stdafx.h and the related cpp file are the precomiled header stuff that VCC creates for you. I just delete them and change the project options to not use precompiled headers; project options->C++ (or code not sure exaclty as i'm not at my normal computer...)->Precompiled headers. If you just remove the files and/or not include them without changing the options then MSVC gives the "unexpected end of file" error. So far I've had no adverse problems with disabling precompiled headers other than a slightly longer build time. |
|
|
|
|
![](images/spacer.gif) |
Andy
|
Posted: Sun Feb 27, 2005 3:15 pm Post subject: (No subject) |
|
|
YESYESYESYESYES!!!! thank you sooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo much... btw, now i have another problem... after i disabled that thing, when ever i start an empty console application, i have to make a new source file, save it in the folder, then move it into the project... does anyone know an easier way? |
|
|
|
|
![](images/spacer.gif) |
|