Question:
c++ bunch of random questions?
2011-01-04 06:11:56 UTC
1
string b = "bone";
how do i find out the SIZE of the word, and how do i retrieve the letters one by one so that i can get
b , o , n , and e separately


#2
what is stream? is it some another storage in the c++ , tat acts like a stack or queue of information to store?


#3
how to TYPE IN a FILE NAME, and you can OPEN IT
so if i type in grocery, i should be able to open grocery.txt which is in the same folder


#4
whats the difference between function and class


#5
wats with the return 0 at the end of file?
Three answers:
Cubbi
2011-01-04 09:33:56 UTC
1.

#include

#include

int main()

{

     std::string b = "bone";

     std::cout << "size is " << b.size() << '\n'

                 << "first letter is " << b[0] << '\n'

                 << "second letter is " << b[1] << '\n';

}



2.

A stream is a model of access to any underlying storage. An input stream has the concept of "reading", which returns successive data elements from the underlying storage (or from the network, or from the keyboard) until the condition "end of stream" occurs. An output stream has the concept of "writing to the stream", which places data into successive positions of the underlying storage (or sends in successive packets over the network, or displays on the screen in successive positions).

In C++, standard input, standard output, files, and strings can be accessed as streams, but other streams may be provided by libraries, such as the boost.asio for network streams or boost.iostream for streams over vectors, compressed file streams, etc.



3.

#include

#include

#include

int main()

{

     std::cout << "type in the file name without extension: ";

     std::string name;

     std::cin >> name;

     name += ".txt";

     std::ifstream fin(name.c_str());

     if(fin)

         std::cout << "File " << name << " opened for reading.\n";

     else

         std::cout << "Could not open file " << name << " for reading.\n";

}



4.

A class is a user-defined type. A function is an object of non-class type which can be executed (by means of operator(), the function call operator). I am not sure how to explain the difference when there is almost nothing in common.



5.

At file scope, return 0; is a syntax error, it can only appear inside a function. You're probably referring to the statement return 0; used at the end of the main function (not at the end of file) in some C++ programs. It is unnecessary, since reaching the closing } of the main function executes return 0;, but many people write it anyway to make main() look more like regular functions.
2011-01-04 06:18:25 UTC
b.size() should print the size, b.char(1) should bring up b, and 2 for o, but double check the functions for a string.

not sure on the rest

5. return sends back a value when the function is done, so return 0 returns 0. if you return a variable the variable value will be passed up to whatever called it, so you can put functions into math equations if you're using it to calculate something, like x=b+function(int) will make x equal to b and whatever function figured out with the int

Like i have a lot of code that uses links to simplify internet stuff, so i'm always passing up strings of html code into other functions.
2016-11-08 02:21:49 UTC
a million) How obssesed are you over your fav char? B- i'm definatly taking fandom to a clean point 2) who's your obsession? Zoro, L and shikamaru 3) (this question is truly substantial o_o) are you able to think of of any megane or meganekko (Characters that positioned on glasses) that are no longer in this checklist? YEAH, there is one megane who isn't listed there: Kogure----> Slam Dunk Sakuragi consistently calls him megane-kun lol, it became into no longer elementary to keep in mind his call xD 4) in case you should create your man or woman harem (constrained to 4 characters), who could be in it? i does no longer create any... 5) to those that have complete Code Geass R2, what'd you think of of the ending (Chu, do no longer answer -_-) ummm, sorry yet i did no longer watch Code Geass ^^ Code Geass or Ichigo a hundred%? idk, i've got no longer watched them... and that i joined your club!! i've got no longer concept that there is a Y!A club, it would be staggering!! ^___^


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...