Dev C++ Cout Does Not Name A Type

P: 1
when I compile it :
hxjnsq@hxjnsq-VirtualBox:~$ g++ stat.cc
stat.cc:19:11: error: ‘ostream’ does not name a type
stat.cc:49:1: error: ‘ostream’ does not name a type
stat.cc: In function ‘int main(int, char**)’:
stat.cc:100:1: error: ‘cerr’ was not declared in this scope
stat.cc:104:1: error: ‘cout’ was not declared in this scope
I don't know why?
  1. //stat.cc
  2. #include<iostream>
  3. #include<string.h>
  4. #include<errno.h>
  5. #include<sys/types.h>
  6. #include<sys/stat.h>
  7. #include<ostream>
  8. class Stat : public stat
  9. {
  10. private:
  11. char *path;
  12. int fd;
  13. public:
  14. Stat(){path=0;fd=-1;}
  15. ~Stat();
  16. Stat & examine(const char *pathname);
  17. Stat & examine(int fd);
  18. int operator(Stat &o);
  19. friend ostream & operator<<(ostream &out , Stat &o);
  20. };
  21. Stat::~Stat()
  22. {
  23. if(path)
  24. delete path;
  25. }
  26. Stat & Stat::examine(const char *pathname)
  27. {
  28. if(path)
  29. delete path;
  30. path=strdup(pathname);
  31. fd=-1;
  32. if(::stat(path,this)-1)
  33. throw errno;
  34. return *this;
  35. }
  36. Stat & Stat::examine(int fd)
  37. {
  38. if(path)
  39. {
  40. delete path;
  41. path=0;
  42. }
  43. this->fd=fd;
  44. if(::fstat(fd,this)-1)
  45. throw errno;
  46. return *this;
  47. }
  48. ostream & operator<<(ostream &out , Stat &o)
  49. {
  50. if(o.fd-1&&!o.path)
  51. {
  52. out<<'No current infomation.'
  53. return out;
  54. }
  55. if(o.path)
  56. cout<<'stat('<<o.path<<'){n';
  57. else
  58. cout<<'fstat('<<o.fd<<'){n';
  59. cout<<'tst_dev=t'<<o.st_dev<<';n'
  60. <<'tst_ino=t'<<o.st_ino<<';n';
  61. cout.setf(ios::oct,ios::basefield);
  62. cout<<'tst_mode=t'<<'0'<<o.st_mode<<';n';
  63. cout.setf(ios::dec,ios::basefield);
  64. cout<<'tst_nlink=t'<<o.st_nlink<<';n'
  65. <<'tst_uid=t'<<o.st_uid<<';n'
  66. <<'tst_gid=t'<<o.st_gid<<';n'
  67. <<'tst_rdev=t'<<o.st_rdev<<';n'
  68. <<'tst_atime=t'<<o.st_atime<<';n';
  69. return out;
  70. }
  71. int Stat::operator(Stat &o)
  72. {
  73. if(fd-1&&!path)
  74. throw EINVAL;
  75. if(o.fd-1 && !o.path)
  76. throw EINVAL;
  77. if(o.st_dev!=st_dev o.st_ino!=st_ino)
  78. return 0;
  79. return 1;
  80. }
  81. int main(int argc,char **argv)
  82. {
  83. int x;
  84. Stat t;
  85. Stat s;
  86. t.examine('./stat');
  87. for(x=1;x<argc;++x)
  88. {
  89. try{
  90. s.examine(argv[x]);
  91. }catch(int e)
  92. {
  93. cerr<<strerror(e)<<':stat(2) of'
  94. <<argv[x]<<'n';
  95. continue;
  96. }
  97. cout<<s<<'n';
  98. cout<<''<<argv[x]<<' is'
  99. <<(st?'same':'not the same')
  100. <<'file as ./statn';
  101. }
  102. return 0;
  103. }
  1. Sorting a Vector in C in Ascending order. A vector in C can be easily sorted in ascending order using the sort function defined in the algorithm header file. The sort function sorts a given data structure and does not return anything. The sorting takes place between the two passed iterators or positions.
  2. #include in top of your main and use std::cout instead of plain cout. If it this doesn't work please enter your code where it says enter code here. – robsn Mar 28 '16 at 22:48 Don't ask what it is for. – zane Mar 28 '16 at 23:02.

Variables are an extremely core concept to most object orientated programming languages. I like to visualize a variable much like a box. We can put things in the box, we can take things out of the box, and at any point we can see what is inside the box. Each box also has a name to which we can refer to it by, and in C++, each box can only hold a certain type of data.

When we create variables we call this the variable declaration, and then when we set them for the first time, we call this the initialization. To declare/toontrack-ezkeys-vst-acoustic-grand-piano-download.html. a variable in C++, we write the function. To declare a basic integer variable called 'age', we could write the following:

求助dev c cin does not name a type 怎么办? 我来答 新人答题领红包. Post your question and get tips & solutions from a community of 449,590 IT Pros & Developers. It's quick & easy.

From this point we can then refer to the variable by its name, so in this case, we can just write 'age' whenever we want to refer to the variable. To initialise the variable we can write its name, followed by the equals sign, followed by the value we want to set the variable to (followed by a semicolon). The value we set it to can be a constant (a value that doesn't change), or another variable of the same type. An operator is a symbol which has a certain meaning in the programming language, in this case, the equals operator, represented by the = symbol, is an operator which sets whatever is on the left of the operator to whatever is on the right.

The constant value we set the variable to depends on the to 5 with something like the following:

We can actually combine the variable declaration and initialization into one more-compact line, like the following:

The 'age' variable now contains the number '5', and we can refer to this '5' by writing 'age' anywhere in our program. We can also change the value of the variable at any point by using the equals operator as we did for the first initialization:

Although this seems purely for convenience at the moment (as we could just write '5', '3', or '21' in place of 'age'), trust me when I say that these become extremely useful and powerful when you start dealing with dynamic logic and user input (the latter of which we'll be covering later in this tutorial).

Just to give an example of accessing the contents of variables by using their names, we could create a new variable called 'age_two' which is set to the value of 'age', and then we can also try outputting one or both of these variables:

To be clear, all this code should be going into the basic program structure which we learnt how to create in the last tutorial. So we want our 'iostream' include for cout, cin, and some other stuff, we want the std namespace, and we want the majority of our code to be going in our 'main' function. So our full code to demonstrate variables so far, which you can compile and run at any point to test the functionality, is as follows:

Some number variables can handle positive and negative numbers, whereas 'unsigned' number variables can only handle positive numbers, although because of this restriction, can hold larger numbers. You can write the signed or unsigned keywords before the and 'short' - numbers with a decimal place in. Floats are accurate to around 6 or 7 digits and are declared using the float type. Float constants can be defined by simply writing a number with a decimal point followed by the 'f' notation. An example of a simple float declaration and initialization to a float constant is as follows:

Precision tune auto care milpitas ca 95035. Care must be taken, however, with float (and other decimal) operations, as rounding and precision problems to do with how the numbers are stored can trip you up (we don't have infinite memory for recurring decimals like 1/3 for example) -- I recommend reading this article for more information on this if you're interested.

Doubles

The 'double' or 'e'. Character variables are declared by using the char type, and character constants are defined by using single quotes (apostrophes) around the character. An example of character declaration and initialization to a character constant is as follows:

Dev C Cout Does Not Name A Type B

Strings

Struct Does Not Name A Type

The lastve talked about string variables in relation to cout before, and as such you should know that string constants are defined by using double quotes. String variables are declared by using the string type, however as strings aren't actually 'primitive' types in C++ (and are instead defined by the standard library of stuff that comes bundled with C++), you are required to #include <string> to use thist strings aren't massively useful, but this is just because we don't really know how to utilize all the functionality of different data-types yet - for example, we don't know how to perform simple mathematics on number types, or how to check the value of booleans to change the logic of the program. All will be revealed in future tutorials.