arrays - Simple General Questions about C++ -
ive moved autoit , learning c++ , problems keep coming up.
the first 1 storing character input. problem have no idea how many characters in line of file (if reading file) or how many letters user going type (in console application).
what best way approach problem?? have heard string class, want avoid becuase dont know how works , leads vunerabilities etc.
secondly...
in c can load shellcode memory, create function pointer, , execute code. there mechanism in c++???
thirdly...
how interpreter iterate through char arrays string output??? (char array[3];) compiler keep track of size of array, or keep reading memory until hits \0 thing???
lastly...
if char * pointers data in memory, why does:
char * title = "program title";
this work??? string literal stored in memory?? how referenced???
thankyou much. appreciate help.
-hyperzap
- investing time in learning std::string worth effort, takes care of lot of hassle you. if don't want take advantage of features in c++, why use c++ , not c?
- you can use same code in c.
- yes, iostream-output of c-style strings outputs until terminating zero. once again, if use std::string not have care such details.
- correct me if i'm wrong, think
title
const char[]
stored on stack.
example:
const char* hello = "hello\0world"; cout << hello; // prints "hello", i.e. terminating 0 (\0)
the reason works:
const char* hello = "hello world"; cout << hello;
is because hello
really "hello world\0";
- in other words, compiler inserts terminating zero.
note std::string
doesn't magic. reads until terminating zero:
string hello = "hello\0world\n"; cout << hello; // still gives "hello"
Comments
Post a Comment