Problem mit Microsoft Visual C++

Heinzi1991

Erfahrenes Mitglied
Hallo liebe Community,

also ich hab ein wirklich blödes Problem mit Visual Studio. Ich hab ein kleines Übungsprogramm geschrieben, damit ich wieder ein bisschen reinkomme!

So auf meinem Laptop, der mit Linux ausgestattet ist, funktioniert das Übungsprogramm einwandfrei. So nun wollte ich es auch auf Windows (Windows 8.1) ausprobieren und hab Microsoft Visual C++ Express und da kommt so eine Fehlermeldung:

"Debug Assertion Failed!

Program: ... dio
2010\Projects\.....
File: f:\dd\vctools\crt_bld\self_x86\crt\src\isctype.c
Line: 56

Expression: (unsigned)(c+1) <= 256

For information ......"

und hier ist die Funktion die nicht so richtig will:
Code:
int woerterzaehlen()
{

	int i = 0;
	int wortzahl = 0;
	string buffer;
	string text;
	string datei;
	ifstream file;


	cout << "Welche Datei soll das Programm einlesen? (Bitte mit Dateiendung) ";
	cin >> datei;

	cout << endl;


	file.open(datei.c_str());

	if(file)
	{
		while(!file.eof())
		{	
			getline(file, buffer);
			text += buffer +"\n";
		}

		file.close();
	}
	else
	{
		cout << "Datei leider nicht vorhanden!" << endl;
	}

//ich glaub das Visual mag diesen Teil nicht//
//da einlesen der Datei noch funktioniert!//

	for(size_t i = 1; i < text.size(); ++i)
	{
		if(isspace(text[i]) && !isspace(text[i - 1]))
		{
			wortzahl++;
		}
	}

	cout << "In dieser Datei sind: " << wortzahl << " Woerter vorhanden!" << endl;
	cout << endl;

	return 0;
}

hoffe mir kann jemand helfen!
 
Hallo Heinzi1991

Wenn du das Programm ausführst siehst du in welcher Zeile und welcher FUnktion das Problem auftritt (F5 in Visual Studio).

/Edit:
Zudem:
C++:
        while(!file.eof())
        {   
            getline(file, buffer);
            text += buffer +"\n";
        }

Nicht gut.

C++:
while(std::getline(file, buffer)) {
   text += buffer + "\n";
}

Viele Grüsse
Cromon
 
also wie im code zu sehen, frag ich welche datei eingelesen werden soll, das funktioniert auch noch, sobald ich enter drücke kommt diese fehlermeldung!
 
Hallo Heinzi1991

Wenn du das Programm in Visual Studio im Debug Modus (F5) startest erhälst du die genaue Zeile in der das Problem stattfindet.

Viele Grüsse
Cromon
 
das ist ja das problem es gibt keine warnungen und keine fehler beim debugen!

hier ein kleiner screenshot:
fehler.jpg


ps: nami auf der rechten seite bitte ignorieren!
 
programm hat einen haltepunkt ausgelöst!

unterbrechen oder weiter?


EDIT:

jetzt ist das gekommen:
Code:
/***
*isctype.c - support is* ctype functions/macros for two-byte multibyte chars
*
*       Copyright (c) Microsoft Corporation. All rights reserved.
*
*Purpose:
*       Defines _isctype.c - support is* ctype functions/macros for
*       two-byte multibyte chars.
*
*******************************************************************************/

#include <stdio.h>
#include <cruntime.h>
#include <ctype.h>
#include <locale.h>
#include <awint.h>
#include <dbgint.h>
#include <mtdll.h>
#include <setlocal.h>


/*
 *  Use GetCharType() API so check that character type masks agree between
 *  ctype.h and winnls.h
 */
#if _UPPER   != C1_UPPER || \
        _LOWER   != C1_LOWER || \
        _DIGIT   != C1_DIGIT || \
        _SPACE   != C1_SPACE || \
        _PUNCT   != C1_PUNCT || \
        _CONTROL != C1_CNTRL
#error Character type masks do not agree in ctype and winnls
#endif  /* _UPPER   != C1_UPPER || \ */



/***
* __chvalidator
*
* Purpose:
*       This function is called by character testing functions in debug
*       versions. This function test for validation of c as character.
*       For improvement in performance, it is not used in non-debug
*       version.  It is available in the static single-thread non-debug
*       build, though, just in case C code that includes ctype.h is compiled
*       /D_DEBUG /ML.
*
*******************************************************************************/

#if defined (_DEBUG)
extern "C" int __cdecl _chvalidator(
        int c,
        int mask
        )
{
        _ASSERTE((unsigned)(c + 1) <= 256);
        return _chvalidator_l(NULL, c, mask);
}

extern "C" int __cdecl _chvalidator_l(
        _locale_t plocinfo,
        int c,
        int mask
        )
{
    _LocaleUpdate _loc_update(plocinfo);

    _ASSERTE((unsigned)(c + 1) <= 256); // => in dieser Zeile ist ein Fehler
    if (c >= -1 && c <= 255)
    {
        return (_loc_update.GetLocaleT()->locinfo->pctype[ c] & mask);
    }
    else
    {
        return (_loc_update.GetLocaleT()->locinfo->pctype[-1] & mask);
    }
}

#endif  /* defined (_DEBUG) */

/***
*_isctype - support is* ctype functions/macros for two-byte multibyte chars
*
*Purpose:
*       This function is called by the is* ctype functions/macros
*       (e.g. isalpha()) when their argument is a two-byte multibyte char.
*       Returns true or false depending on whether the argument satisfies
*       the character class property encoded by the mask.
*
*Entry:
*       int c - the multibyte character whose type is to be tested
*       unsigned int mask - the mask used by the is* functions/macros
*                  corresponding to each character class property
*
*       The leadbyte and the trailbyte should be packed into the int c as:
*
*       H.......|.......|.......|.......L
*           0       0   leadbyte trailbyte
*
*Exit:
*       Returns non-zero if c is of the character class.
*       Returns 0 if c is not of the character class.
*
*Exceptions:
*       Returns 0 on any error.
*
*******************************************************************************/

extern "C" int __cdecl _isctype_l (
        int c,
        int mask,
        _locale_t plocinfo
        )
{
        int size;
        unsigned short chartype;
        char buffer[3];
        _LocaleUpdate _loc_update(plocinfo);

        /* c valid between -1 and 255 */
        if ( c >= -1 && c <= 255 )
            return _loc_update.GetLocaleT()->locinfo->pctype[ c] & mask;

        if ( _isleadbyte_l(c >> 8 & 0xff, _loc_update.GetLocaleT()) )
        {
            buffer[0] = (c >> 8 & 0xff); /* put lead-byte at start of str */
            buffer[1] = (char)c;
            buffer[2] = 0;
            size = 2;
        } else {
            buffer[0] = (char)c;
            buffer[1] = 0;
            size = 1;
        }

        if ( 0 == __crtGetStringTypeA(
                    _loc_update.GetLocaleT(),
                    CT_CTYPE1,
                    buffer,
                    size,
                    &chartype,
                    _loc_update.GetLocaleT()->locinfo->lc_codepage,
                    _loc_update.GetLocaleT()->locinfo->lc_handle[LC_CTYPE],
                    TRUE) )
        {
            return 0;
        }

        return (int)(chartype & mask);
}

extern "C" int __cdecl _isctype (
        int c,
        int mask
        )
{
    if (__locale_changed == 0)
    {
        return __initiallocinfo.pctype[ c] & mask;
    }
    else
    {
        return _isctype_l(c, mask, NULL);
    }
}

zeile 56 tritt der fehler auf; _ASSERTE.....
 
Zuletzt bearbeitet:
Hallo Heinzi1991

Du siehst bereits den Pfeil auf der fehlerhaften Zeile, wenn du auf Break drückst verschwindet auch die Meldung.

Viele Grüsse
Cromon
 
Wenn du unten rechts im Callstack schaust siehst du in welcher Zeile von dir es stattfindet. Wenn du den callstack nicht offen hast: Debug -> Windows -> Callstack
 
Zurück