View previous topic :: View next topic |
Author |
Message |
Janka
Joined: 14 Nov 2005 Posts: 19 Location: Jelgava
|
Posted: Thu Nov 17, 2005 7:08 pm Post subject: Debug Error! |
|
Kaads, paliidiet luudzu!
Quote: |
Microsoft Visual C++ Debug Library
Debug Error!
Program: d:\Visualstudio\testing\strings\debug\strings.exe
HEAP CORRUPTION DETECTED: after Normal block (#114) at 0x00355BC8
CRT detected that the application wrote to memory after end of heap buffer.
(Press Retry to debug the application)
Abort Retry Ignore
|
izlec shaadaa vietaa:
type* old = str (= "Hello!\0")
Quote: |
template{
type = char
}
|
Last edited by Janka on Thu Nov 17, 2005 7:50 pm; edited 1 time in total |
|
Back to top |
|
|
bubu Indago Uzvarētājs
Joined: 23 Mar 2004 Posts: 3223 Location: Riga
|
Posted: Thu Nov 17, 2005 7:23 pm Post subject: |
|
Kas ir str()?
Kāpēc tur ir vienādības zīme aiz ( ?
Ko nozīmē tavs "template { type=char }" ? |
|
Back to top |
|
|
Janka
Joined: 14 Nov 2005 Posts: 19 Location: Jelgava
|
Posted: Thu Nov 17, 2005 7:41 pm Post subject: |
|
type* str;
aiz ( = tap'ec, ka es nor'adu kas tas ir) nu kaut kaa taa, laikam vajadzeeja iekavu vietaa lietot /* un */
type ir template, kas ir char - nu kaut kaa taa... |
|
Back to top |
|
|
Vecais_Dumais_Laacis Guru
Joined: 29 Jan 2004 Posts: 800
|
Posted: Thu Nov 17, 2005 7:58 pm Post subject: |
|
po moimu tev old ir pointeris uz konstantu stringu tb tu nevari vinju dzeest _________________ ...un ja bites buutu laachi... |
|
Back to top |
|
|
bubu Indago Uzvarētājs
Joined: 23 Mar 2004 Posts: 3223 Location: Riga
|
Posted: Thu Nov 17, 2005 9:43 pm Post subject: |
|
Joprojām nesaprotu to str() funkciju un = zīmi aiz ( iekavas. |
|
Back to top |
|
|
Janka
Joined: 14 Nov 2005 Posts: 19 Location: Jelgava
|
Posted: Fri Nov 18, 2005 12:25 am Post subject: |
|
ok, pierakstiishsu veelreiz...
type* old = str (= "Hello!\0") == type* old = str /* = "Hello\0" */
Ceru, ka tagad saprati piekriitu nebiju uzrakstiijis pareizi
Quote: |
po moimu tev old ir pointeris uz konstantu stringu tb tu nevari vinju dzeest
|
Nu nav uz konstantu, to jau es arii iedomaajos, ja kaads vareetu pateikt kur, vareetu ielikt netaa lai var apluukot... |
|
Back to top |
|
|
bubu Indago Uzvarētājs
Joined: 23 Mar 2004 Posts: 3223 Location: Riga
|
Posted: Fri Nov 18, 2005 12:48 am Post subject: |
|
Ah nu beidzot sapratu. Tas str ir kautkāds cits mainīgais! Tak vajag uzreiz normāli rakstīt..!
A kā tu šamam piešķir vērtību, parādīsi?
Ta kautvai paste.php.lv ieliec (tikai dieva dēļ, nevis visu, bet fragmentu tikai!), vai ja nav garš kods, tad te pat [code] bbtagos. |
|
Back to top |
|
|
Janka
Joined: 14 Nov 2005 Posts: 19 Location: Jelgava
|
Posted: Fri Nov 18, 2005 12:18 pm Post subject: |
|
nav jau garsh (kaa nekaa tikai tests):
Code: |
#pragma once
template<class type>
class STRING{
private:
type* data;
int used, allocated;
public:
STRING():used(1),allocated(1),data(0){
data = new type[1];
data[0] = '\0';}
// a STRING from string
STRING(type* str):used(0),allocated(0),data(0){
if(!str) return;
// get size of string
int lenght = 0;
const type* p = str;
while(*p){
p++;
lenght++;}
used = allocated = lenght+1;
data = new type[used];
for(int i=0;i<used;i++) data[i]=str[i];
data[used]='\0';}
// pieliidzinaashanas operators
void operator=(const type* str) {
if(!str) return;
// get size of string
int lenght = 0;
const type* p = str;
while(*p){
p++;
lenght++;}
used = allocated = lenght+1;
data = new type[used];
for(int i=0;i<used;i++) data[i]=str[i];
data[used]='\0';
}
// construct string from other string
STRING(const STRING<type>& other):used(0),allocated(0),data(0){
*this = other;}
// destructor
~STRING(){
delete[] data;} // shitaa vieta arii karaas
// return string
type* c_str(){ return data; }
// return size
int size(){ return used-1; }
// append a char
void append(type ch){
if(used+1>allocated) reallocate(used+1);
data[used-1]=ch; data[used]='\0';
used+=1;
}
// append a string
void append(type* str) {
if(!str) return;
// a size of string
int lenght=0;
const type* p = str;
while(*p){
p++;
lenght++;}
if(used+lenght>allocated) reallocate(used+lenght);
for(int i=0;i<lenght;i++) data[used+i]=str[i];
used = used+lenght;
data[used-1]='\0';
}
type operator[](int index) {
if(index<0||index>=used) return;
return data[index];
}
private:
void reallocate(int new_size){
if(new_size==allocated) // no need to reallocate memory
return;
type* old = data;
data = new type[new_size];
allocated = new_size;
int lenght = used < new_size ? used : new_size;
for(int i=0;i<lenght;i++) data[i]=old[i];
data[lenght]='\0';
if(used>allocated) used = allocated;
delete [] old;
}
};
typedef STRING<char> stringc;
#include <stdlib.h>
#include <iostream>
using namespace std;
int main(){
stringc str;
str = "Hollo!!!\n";
cout<<str.c_str();
str.append('A');
str.append("ste\n");
stringc s;
s = "K-kas";
str.append(s.c_str());
str.append('\n');
cout<<str.c_str();
system("PAUSE");
return 0;
}
|
|
|
Back to top |
|
|
bubu Indago Uzvarētājs
Joined: 23 Mar 2004 Posts: 3223 Location: Riga
|
Posted: Fri Nov 18, 2005 3:19 pm Post subject: |
|
A kas notiek, ja izvāc cout'us? Tad arī tas pats?
Un kas vainas STL string klasei, ka negribi to izmantot? |
|
Back to top |
|
|
|