Learning C++/lua
#1
Does anyone know why this code:
Quote:#include <iostream>
#include <stdio.h>
int main()
{
cout << "IT WORKS!\n";
cout << "\nPress Enter to continue" << endl;
getchar();
return 0;
}
doesn't work? i get an error in the
cout << "IT WORKS!\n";
cout << "\nPress Enter to continue" << endl;
Reply
Thanks given by: PCPlayerLV
#2
use std::cout instead of just cout

Also, next time you get an error, be sure to post the actual error message
Reply
Thanks given by:
#3
thank you Smile its weard because the book says "cout" not "std::cout" :O
Reply
Thanks given by:
#4
maybe somewhere they have a
Code:
using namespace std;
Reply
Thanks given by:
#5
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.
Reply
Thanks given by:
#6
thanks,

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:
Code:
#include <iostream>
#include <fstream>
using namespace std;

//the remove part
int Remove()
{
  if( remove( "Settings.ini" ) != 0 )
    perror( "Error deleting file" );
  else
    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;
  myfile.open ("settings.ini");
  myfile << "[Server]\n" << "port=" << Port << "\nmaxplayers=" << MaxPlayers << "\nDescription=" << Description;
  myfile.close();
  return 0;
}
Reply
Thanks given by: PCPlayerLV
#7
try using
Code:
string Description;

?
Reply
Thanks given by: PCPlayerLV
#8
it works but i can only have one word. if i type in: New Description
it only shows New Sad
Reply
Thanks given by:
#9
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:
http://www.cplusplus.com/reference/string/getline/
Reply
Thanks given by: PCPlayerLV , Francisdaumb
#10
yay thanks it works Smile
i can now get things like this:
Quote:[Server]
port=25565
maxplayers=20
Description=Description here please Smile

[Worlds]
DefaultWorld=Wpr;d

[Plugins]
Plugin=Core
Plugin=ChatLog

[HelpPlugin]
ShowPluginNames=1
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)