11 Replies - 1013 Views - Last Post: 03 February 2012 - 08:54 AM Rate Topic: -----

#1 amit2011  Icon User is offline

  • D.I.C Head

Reputation: -13
  • View blog
  • Posts: 64
  • Joined: 17-March 11

Microsoft Visual c++....(which project to open)

Posted 03 February 2012 - 01:35 AM

I've just started with ms visual c++ 2010..
Having some ideas that it consists of developng win32, console application etc.

I want to create a blank project, which does'nt consists of the directive #include<stdafx.h>,
i.e i want to create a project same as in devc++(blank project).

I should open win32 or clr or general or ATL project??
Basically i want to perform file handling using libraries(I am not using devc++ or turboc as i read somewhere that ms visual c++ supports more libraries)?

I don't want to create any application whcih includes api functions as the code developed should work on any os
(windows, solaris etc).

Currently using WindowsXP..

Is This A Good Question/Topic? 0
  • +

Replies To: Microsoft Visual c++....(which project to open)

#2 norman1312  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 62
  • Joined: 08-September 11

Re: Microsoft Visual c++....(which project to open)

Posted 03 February 2012 - 02:05 AM

In that case you should start with a blank console application.
That way you can control everything, and create whatever files you need, and not get involved in anything connected with the api.
Was This Post Helpful? 0
  • +
  • -

#3 amit2011  Icon User is offline

  • D.I.C Head

Reputation: -13
  • View blog
  • Posts: 64
  • Joined: 17-March 11

Re: Microsoft Visual c++....(which project to open)

Posted 03 February 2012 - 02:17 AM

View Postnorman1312, on 03 February 2012 - 02:35 PM, said:

In that case you should start with a blank console application.
That way you can control everything, and create whatever files you need, and not get involved in anything connected with the api.


Ok, but its showing an error when i include <fstream.h>....( error as no such file or directory)..



#include<iostream>
#include<conio.h>
#include<stdio.h>
#include<fstream.h>
void main()
{
   
   
   long start,end1;
   ifstream newfile ("dddd.txt");  //ifstream is used for input
   start= newfile.tellg();
   
   newfile.seekg(0, ios::end);
   end1 = newfile.tellg();
   newfile.close();
   cout << "size is: " << (end1-start) << " bytes.\n";
   getch();
 }



Was This Post Helpful? 0
  • +
  • -

#4 norman1312  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 62
  • Joined: 08-September 11

Re: Microsoft Visual c++....(which project to open)

Posted 03 February 2012 - 02:30 AM

You shouldn't need it. Try adding
using namespace std;


Was This Post Helpful? 0
  • +
  • -

#5 amit2011  Icon User is offline

  • D.I.C Head

Reputation: -13
  • View blog
  • Posts: 64
  • Joined: 17-March 11

Re: Microsoft Visual c++....(which project to open)

Posted 03 February 2012 - 02:34 AM

View Postnorman1312, on 03 February 2012 - 03:00 PM, said:

You shouldn't need it. Try adding
using namespace std;




same error by adding using namspace std.....
and after removing fstream and adding using namspace std(dozen of errors)
:(

This post has been edited by amit2011: 03 February 2012 - 02:36 AM

Was This Post Helpful? 0
  • +
  • -

#6 norman1312  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 62
  • Joined: 08-September 11

Re: Microsoft Visual c++....(which project to open)

Posted 03 February 2012 - 02:40 AM

Exactly what errors?
Was This Post Helpful? 0
  • +
  • -

#7 amit2011  Icon User is offline

  • D.I.C Head

Reputation: -13
  • View blog
  • Posts: 64
  • Joined: 17-March 11

Re: Microsoft Visual c++....(which project to open)

Posted 03 February 2012 - 02:46 AM

Error 1 error C2079: 'newfile' uses undefined class 'std::basic_ifstream<_Elem,_Traits>'
Error 2 error C2440: 'initializing' : cannot convert from 'const char [9]' to 'int'
Error 3 error C2039: 'tellg' : is not a member of 'System::Int32'
Error 4 error C2039: 'seekg' : is not a member of 'System::Int32'
Error 5 error C2039: 'tellg' : is not a member of 'System::Int32'
Error 6 error C2039: 'close' : is not a member of 'System::Int32'


The above stated errors, by removing <fstream>
Was This Post Helpful? 0
  • +
  • -

#8 Feuer  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 57
  • Joined: 15-June 11

Re: Microsoft Visual c++....(which project to open)

Posted 03 February 2012 - 02:59 AM

Try including <fstream> instead of <fstream.h>.
Was This Post Helpful? 2
  • +
  • -

#9 norman1312  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 62
  • Joined: 08-September 11

Re: Microsoft Visual c++....(which project to open)

Posted 03 February 2012 - 03:06 AM

I was just about to say that!
Was This Post Helpful? 1
  • +
  • -

#10 amit2011  Icon User is offline

  • D.I.C Head

Reputation: -13
  • View blog
  • Posts: 64
  • Joined: 17-March 11

Re: Microsoft Visual c++....(which project to open)

Posted 03 February 2012 - 03:07 AM

View PostFeuer, on 03 February 2012 - 03:29 PM, said:

Try including <fstream> instead of <fstream.h>.


Thnks a lot.. :)
Now its running.

Can you suggest me that for file handling instead of doing this way,
is there any otherw ay out to find the size of a file(which is more than 2-3 gb)..

I have done it by using windows api functions,
but as this code can be used in other os's, so I think Windows API functions like Create File will not work.

Is there any alternative??
Was This Post Helpful? 0
  • +
  • -

#11 amit2011  Icon User is offline

  • D.I.C Head

Reputation: -13
  • View blog
  • Posts: 64
  • Joined: 17-March 11

Re: Microsoft Visual c++....(which project to open)

Posted 03 February 2012 - 03:22 AM

View Postnorman1312, on 03 February 2012 - 03:36 PM, said:

I was just about to say that!


Thnks to you too..
Was This Post Helpful? 0
  • +
  • -

#12 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Microsoft Visual c++....(which project to open)

Posted 03 February 2012 - 08:54 AM

If you are on windows you have a number of options to get the file size:

GetFileSizeEx() -- works well but requires the file to be opened to read the size. This can be inconvenient.

GetFileAttributesEx() -- works a little better. however the file size is a 64bit value broken up into 2 32bit values in the WIN32_FILE_ATTRIBUTE_DATA.

Since you seem to be on Visual Studio you can use unsigned long long or unsigned __int64 to capture the file size.

so here is an example:
#include <iostream>
#include <Windows.h>

using namespace std;
unsigned long long getFileSize(const TCHAR *fileName);

int main(int argc, char* args[]) {

    if( argc < 2) {
        cerr << "Please specify a file name" << endl;
        return 1;
    }
    unsigned long long filesize = getFileSize(args[1]);
    if (filesize != -1) {
        cout << "file size: " << filesize << endl;
    } else {
        cout << "Error getting file size" << endl;
    }

    return 0;
}

unsigned long long getFileSize(const TCHAR *fileName)
{
    unsigned long long retVal = 0;
    WIN32_FILE_ATTRIBUTE_DATA fileInfo;

    if (NULL == fileName) { return -1; }

    if ( !GetFileAttributesEx(fileName, GetFileExInfoStandard, &fileInfo) ) {
        return -1;
    }
    retVal = fileInfo.nFileSizeHigh;
    retVal = (retVal << 32) + fileInfo.nFileSizeLow;
    return retVal;
}


you might be able to do some fancy pointer casting to get the filesize but I just went with a little math.

I tested it out on some OS install ISO images and it seems to return the proper file size.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1