kux 55 Junior Poster

i have a
ifstream m_ifsInput
variable and I try to open a file like this:
m_ifsInput.open( sFileName.c_str() );
where sFileName is a std::wstring variable
the error i get when compiling with g++

no matching function for call to ‘std::basic_ifstream<char, std::char_traits<char> >::open(const wchar_t*)’

the thing is the same thing compiles well uner windows. Looking at the error i get with g++ would mean that there is no open method that takes a wchar_t* as parameter, but then, why the heck does it compile with visual studio ??? I mean it's a standard library function.. these should port ...

kux 55 Junior Poster

if u pass a std::vector by value to a function, does all of it's content get copyed?

thx

kux 55 Junior Poster

using visual studio 2005
this is the problem:

say i have a solution with 3 projects:
first - has some usefull utils functions and i build it as a static library
second - a project that uses the utils. I link with the first and build as a static library
third - a project built as exe that links to the second

now, the thing is when i build the third ( the exe ) i get an "unrezolved external simbol" to the functions from the first project that I use in the second

this is how i write first

first.h
#ifndef FIRST_H
#define FIRST_H

void usefull();

#endif

first.cpp
#include "first.h"
void usefull() {};

maybe I need to add some keywords to the function definition and declaration?
thx

kux 55 Junior Poster

Actually, it is possible. You need to use token concatenation. #define DEFINE_FUNC( n ) void func_ ## n() You would use it in the normal way: DEFINE_FUNC( 12 ); The preprocessor would turn that into: void func_12(); While I can't imagine why you want to do this, there are, in fact, legitimate reasons to do token concatenation (which goes a long way into explaining why the preprocessor can do it at all).

Hope this helps.

true, what i meant to say is that if u have

DEFINE_FUNC (12)
the preprocessor should replace with 12 function declarations named func_1 func_2 ... func_12
so as Dave said, the looping is the problem

anyway as I said, I managed to carry out my stuff without using this, but if someone can figure out how to do the macro thingie I would be thankfull. I heard something that boost's preprocessor library can do that. didn't get to try it out : http://boost.org/libs/preprocessor/doc/ref/repeat.html.

cheers

Dave Sinkula commented: Boost never ceases to continue to amaze me. +13
kux 55 Junior Poster

ok, thx 4 the help
managed to work arround without the help of that macro

kux 55 Junior Poster

hello,

does anyone know if I can write a macro that takes a number as argument and according to that number declares a variable number of functions ?
ex:

DEFINE_FUNC( 4 );

is replaced with

void func_1();
void func_2();
void func_3();
void func_4();

thx

kux 55 Junior Poster

>vector<string> vect;
>copy( istream_iterator<string>(is) , istream_iterator<string>() , vect.begin() );
The vector is empty, and copy won't call push_back for you. You need to add a back_inserter to the destination or copy will write to memory that you don't own:

copy( istream_iterator<string>(is) ,
  istream_iterator<string>() , back_inserter( vect ) );

You also need to include <algorithm> if you plan to use the sort function.

true, :P thx

kux 55 Junior Poster

i have a problem... i wanna make a function that takes a string as input splits it, storing the resulting strings in a vector<string> and then sort it

#include <iostream>
#include <vector>
#include <iterator>
#include <sstream>

using namespace std;

vector<string> split( const string &sInput  )
{
	istringstream is( sInput );
	vector<string> vect;
	copy( istream_iterator<string>(is) , istream_iterator<string>() , vect.begin() );
	sort( vect.begin() , vect.end() );
	return vect;

}

int main(int argc, char* argv[])
{
	if(argc != 2) return 1;
	string sForSplit = argv[1];
	vector<string> vect;
	vect = split( sForSplit );
	ostream_iterator<string> os( cout ,"\n");
	copy ( vect.begin(), vect.end() , os );

}

it compiles, but when i run it i get Segmentation Fault

can anyone explain me why? i don't want to implement the function without the istream_iterator, done that before, i just want to know where does the runtime error occur and why.
thx

kux 55 Junior Poster

lol, it replaced : fs with the smiley , u know what i mean actually :P :))

kux 55 Junior Poster

I don't think it is supported. A replacement might be fscanf() + some extra code, but it really depends on what you are doing with with vfscanf.

hmmm, what i am doing is that i want to wrap my formated file read in a File class that i design myself so that it throws exceptions for every problem that might occur.
what i want to is to have a Scan method in my File class that looks like

void File::Scan ( const char * Format, ... )  
{
    va_list objArgs;
    va_start( objArgs, pcFormat );
    vfscanf( m_pFile, pcFormat, objArgs ); // m_pFile is the file handle
    va_end( objArgs );
}

this is actually wraping fscanf in File::Scan

kux 55 Junior Poster

As i knew the <stdarg.h> header should have the following function

int vfscanf(FILE *stream, const char *format, va_list ap);

but under Visual Studio 2005, after including the header and calling the function i get
'vfscanf': identifier not found

if the function is not declared, can u tell me some simmilar functions that do the same
thing and have the same parameters?

thx

kux 55 Junior Poster
struct A
{
  A( int i ) throw(char,int,double) : value(i) {}
  int value ;
};

struct B : A
{
  B() throw(char,int,double) ;
};

B::B() throw(char,int,double) : A(20) {}

thx

kux 55 Junior Poster

i noticed that when u compile with visual C++ u don't need the throw statement in function headers, but when u compile with g++ u need to explicitly mention all the exceptions u're function might throw.
i mean:

void functionx() throw ( exception1 , exception 2)
{
//blabla
throw exception1;
//blabla
throw exception2;
}

but if u have a base class A and a derived class B, how do u write the throw statement for the B class constructor?
because

B::B() : a() throw ( exception1 , exception2 )
gives the
errorr C2612: trailing 'throw' illegal in base/member initializer list

thx

kux 55 Junior Poster

yes, true. I documented on RAII too, the solution is to close in the File object destructor
thx for the help

kux 55 Junior Poster

The STL file close functions don't throw exceptions. They will set the fail bit if pending output could not be written before closing, but that's all.

The general rule is that file close functions should not throw exceptions...

i'm not talking about the stl file close. when i mean close throws an exception i mean my "homemade" close method of my
homemade" File class ( that actually wraps the stl close in a "object oriented manner") throws that exception.
i would also like to know why would close functions not throw exeptions.
thx

kux 55 Junior Poster

ok, i have a question

say i have a class that wraps all file accesing functions ( basicly opening, reading and closing )
all these file handling functions throw a FileException exception
i have a try block in that i open, read and close my file using the above mentioned class
let's say read method throws a FileException
that means the close method is not getting called, so in order to close the file i have to close it
in the catch (FileException &blabla) block ...
but what if the close method inside the catch also throws an exception?
so the question is: how do i desing the try catch block so that no FileException can be left uncatched

thx

kux 55 Junior Poster

it's ok, i found the problem.
had nothing to do with memory allocs, i forgot to include a header required for the exception i was throwing. the wierd thing is that i had no compile error, just this strange runtime error

thx for the help

kux 55 Junior Poster

yes, i catch the exception in the program that calls the constructor.
the thing is the class that that the constructor belongs to is built in a static library, while the program that calls the constructor is built as an exe(different projects, same solution, vstudio 2005..blabla). don't know, could this be the problem?

kux 55 Junior Poster

here is the thing:
i have a constructor that calls a member function, the function throws an exception, i catch the exception in the constructor, free all dynamic allocated variables and then rethrow the exception

when i rethrow i get this:
Unhandled exception at 0x10210e32 (msvcr80d.dll) in Test.exe: 0xC0000005: Access violation reading location 0xcdcdcdc8.

and i'm stuck in dbgheap.c at line 1595

any help is welcomed, thx :)