Cuberite Forum
Learning C++/lua - Printable Version

+- Cuberite Forum (
+-- Forum: Off Topic (
+--- Forum: Off Topic Discussion (
+--- Thread: Learning C++/lua (/thread-641.html)

Pages: 1 2 3 4

Learning C++/lua - NiLSPACE - 12-04-2012

Does anyone know why this code:
Quote:#include <iostream>
#include <stdio.h>
int main()
cout << "IT WORKS!\n";
cout << "\nPress Enter to continue" << endl;
return 0;
doesn't work? i get an error in the
cout << "IT WORKS!\n";
cout << "\nPress Enter to continue" << endl;

RE: Learning C++ - FakeTruth - 12-04-2012

use std::cout instead of just cout

Also, next time you get an error, be sure to post the actual error message

RE: Learning C++ - NiLSPACE - 12-04-2012

thank you Smile its weard because the book says "cout" not "std::cout" :O

RE: Learning C++ - FakeTruth - 12-04-2012

maybe somewhere they have a
using namespace std;

RE: Learning C++ - xoft - 12-05-2012

In older C++, cout used to be global, you could use it without the std prefix. But that was years ago, and only in some compilers.

RE: Learning C++ - NiLSPACE - 12-10-2012


i'm now trying to make a configuration file just like with my build script but than in c++ just to practise.
i'm now struggeling that i can't put letters in a variable. with the server description part if i now put letters in it, it says 0 in the settings.ini.
if you want to look in the "source" this is it:
#include <iostream>
#include <fstream>
using namespace std;

//the remove part
int Remove()
  if( remove( "Settings.ini" ) != 0 )
    perror( "Error deleting file" );
    puts( "File successfully deleted" );
  return 0;

//the server configuration
int main()
int Port;
  int MaxPlayers;
  int Description;

    cout << "Please Enter your server port (default minecraft is 25565): ";

    cin >> Port;

    cout << "Please enter the maxplayers able to join: ";

    cin >> MaxPlayers;

    cout << "Please enter your server description: ";

    cin >> Description;
  ofstream myfile; ("settings.ini");
  myfile << "[Server]\n" << "port=" << Port << "\nmaxplayers=" << MaxPlayers << "\nDescription=" << Description;
  return 0;

RE: Learning C++ - FakeTruth - 12-10-2012

try using
string Description;


RE: Learning C++ - NiLSPACE - 12-10-2012

it works but i can only have one word. if i type in: New Description
it only shows New Sad

RE: Learning C++ - xoft - 12-10-2012

I suppose that cin operator >> extract only until any whitespace. The solution would be to repeat reading from cin until you get a '\n', and concatenate everything you've read into a string.

I never particularly liked streams, so I've never actually learnt much about them.

Seems there's a std::getline() just for this purpose:

RE: Learning C++ - NiLSPACE - 12-11-2012

yay thanks it works Smile
i can now get things like this:
Description=Description here please Smile