-
i get illegal operation.
im new in C++
this is only a sample code:
Code:
#include <iostream>
#include <fstream>
using namespace std;
int main () {
char *a;
char *b;
char *c;
char *d;
ifstream ab ("word.txt");
ifstream bb ("wordlist.txt");
ab>>c; //line 11 b=c;
cout<<b;
bb>>d; //line 14
a=d;
cout<<b<<a;
cin.get();
}
note: the text with red font is the coz of "illegal operation" but if i change it to a same variable i dont recieve illegal operation but whenever line 14 is executed both variable b and a change to the value from the document.
this is the problem if i use same variable to line 11 and 14:
i change the variable c to d from line 11.
ab>>d;
b=d; meaning if string from the word.txt is aaaa, b = "aaaa"
when line 14 is executed
ab>>d;
a=d; if string from wordlist.txt is bbbb supposed to be a= "bbbb"
but b is also become b= "bbbb"
any help!!
-
Your pointers a, b, c and d are pointing at "random" locations, you need to allocate some memory, or otherwise point at some valid memory location.
--
Mats
-
Just use std::string instead of raw char pointers.
-
i am new in C++ and dont know how to allocate memory can you give me a sample? thanks
-
Just use std::string instead.
Here's a quick introduction:
http://www.cprogramming.com/tutorial/string.html