473,385 Members | 1,275 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

VC++ CMD Console App

Alright, so I'm trying to re create Command Prompt and it's sort of working, but it doesn't parse argument's properly. The code and output is below.

Code:
Expand|Select|Wrap|Line Numbers
  1. #include "stdafx.h"
  2. #include <windows.h>
  3. #include <iostream>
  4. #include <string>
  5. using namespace std;
  6.  
  7. int _tmain(int argc, _TCHAR* argv[])
  8. {
  9.     while(1){
  10.     string var = "";
  11.     cin >> var;
  12.     if(var == "exit"){
  13.         break;
  14.     };
  15.     int ret = system(var.c_str());
  16.     if(ret == 0){
  17.  
  18.     } else {
  19.  
  20.     };
  21.  
  22.     };
  23. }
  24.  
Output:
Color 0a
'0a' is not recognized as an internal or external command,
operable program or batch file.

Can anyone help me out here?

p.s: I'm using a Win32 Console App
Sep 28 '08 #1
6 2188
boxfish
469 Expert 256MB
The cin's >> operator stops at any whitespace, but it looks like you are expecting it to stop at a newline only. "color" is read as one command, then in the next iteration, it gets "0a" as another. I'm trying to think of a way to get a whole line from the input stream, but the only way I can think of is this, which looks slow and clunky to me.
Expand|Select|Wrap|Line Numbers
  1. string var;
  2. char gotten;
  3. while ((gotten = cin.get()) != '\n') {
  4.     var += gotten;
  5. }
  6.  
BTW, you don't need to put semicolons after the closing braces of if statements and loops. That's just for classes and structs.

Hope this helps some.
Sep 28 '08 #2
Banfa
9,065 Expert Mod 8TB
I'm trying to think of a way to get a whole line from the input stream,
What's wrong with using getline?
Sep 28 '08 #3
boxfish
469 Expert 256MB
Awsome, I had no idea that worked with strings. I only knew how to do it with a char* buffer.
Sep 28 '08 #4
Thanks for the help guy's, I've got it working now.
On a side note, have any of you used LuaBind before?
If so, how would I implement it into my app to use DoString <code>?
Sep 29 '08 #5
Banfa
9,065 Expert Mod 8TB
Sorry I haven't used that.
Sep 29 '08 #6
Darn, okay.
Too Short.
Sep 29 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Weston Fryatt | last post by:
(Sorry for spamming multiple groups, But I need a solution to this problem) I think this should be a simple question on Memory Allocation in a managed DLL and passing a memory pointer over to an...
7
by: MuZZy | last post by:
HI I just wonder if someone can help me with this: I have a windows app project developed on VC++ 6.0. I need to adapt it to be able to compile as a console app as well (So it would call main()...
2
by: SHC | last post by:
Hi all, I read the Microsoft KB Q815658 "How to read the XML data from a file using Visual C++ .NET" and tried to follow the steps of executing its source code in my VC++ .NET 2003 under Console...
1
by: SHC | last post by:
Hi all, I did the "Build" on the attached code in my VC++ .NET 2003 - Windows XP Pro PC. On the c:\ screen, I got the following: Microsoft Development Environment An unhandled exception of type...
6
by: SHC | last post by:
Hi all, I created an application from the Console Application (.NET) of VC++ .NET 2003, and I did "Build" the application of the attached .cpp file, volcanoes.xml and geology.dtd on my VC++ .NET...
0
by: Bill Sun | last post by:
Hi, When I want to using the ADO examples:ADOXCreateDatabaseX.cpp applied by MSDN 2003 on the VC.net2003. the compile always told me errors, like: c:\project\console\console\console.cpp(22):...
5
by: Scott Chang | last post by:
Hi all, I copied a set of VC++ version 6 source code of the 'cppdll'(2 projects) from a website and put the cppdll.cpp, cppdll.def, cpp.h, (as the 1st project) and test.cpp (as the 2nd project)...
1
by: Bern McCarty | last post by:
What do you make of this? I cannot tell for sure but it almost seems as the the transition thunk to get back from the native bool method to the managed caller is looking at eax and, if any bit is...
4
by: Shil | last post by:
Hi, In VC++.Net 2005 visual studio, if I create a new winform drag and drop a button, then double click it to write click event code, then it auto generates the template code for the event in...
2
by: SheetalGandhi24 | last post by:
Hi I need to use the System.IO namespace in the Win32 console application. Any clues for doing the same? Basically, I need to load the files of a particular folder in an array. I need to do...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.