console-application

How do I call main() in my main cpp file from a seperate cpp file?

青春壹個敷衍的年華 提交于 2019-12-02 13:37:14
I'm making a class that displays a message to the user and asks them if they want to return to the start of the program, but the message function is in a separate class from where my main() is located. How do I access the main() function from a different class? This is an example of the stuff I want to do: main.cpp file: int main() { Message DisplayMessage; DisplayMessage.dispMessage(); return 0; } Message.cpp file: void dispMessage(void) { cout << "This is my message" << endl; //now how do I call main again in the main.cpp file? } Thanks! In C++ it is illegal for a program to call main itself

.net console app lifecycle - working around a pre-start initialization error from BuildManager.GetReferencedAssemblies

烂漫一生 提交于 2019-12-02 11:06:18
问题 I'm trying to iterate through the referenced assemblies in my console app. I have been doing this with BuildManager.GetReferencedAssemblies in other projects, but in my console application, I get an InvalidOperationException: This method cannot be called during the application's pre-start initialization stage. To my knowledge, there isn't a way to delay execution in a console app. You do it in static void Main, or you don't do it at all... Anyone have any suggestions on how to get around this

Out of Memory Exception when using File Stream Write Byte to Output Progress Through the Console

不想你离开。 提交于 2019-12-02 11:02:55
问题 I have the following code that throws an out of memory exception when writing large files. Is there something I'm missing? I am not sure why it is throwing an out of memory error as I thought the Filestream would only use a maximum of 4096 bytes for the buffer? I am not entirely sure what it means by the Buffer to be honest and any advice would be appreciated. public static async Task CreateRandomFile(string pathway, int size, IProgress<int> prog) { byte[] fileSize = new byte[size]; new

Trying to get StandardOutput after running a console process

橙三吉。 提交于 2019-12-02 10:15:41
问题 I can run a console process using the following C# code. The goal is also to collect all the output from such process: System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.StartInfo.Arguments = commandLine; proc.StartInfo.FileName = "signtool.exe"; proc.StartInfo.RedirectStandardOutput = true; proc.StartInfo.UseShellExecute = false; proc.Start(); if (proc.WaitForExit(10000)) { Debug.WriteLine(proc.StandardOutput.ReadToEnd()); } What I receive is this: "Done Adding

cin.get() is non-blocking

筅森魡賤 提交于 2019-12-02 10:05:03
问题 I have the same problem as mentioned in the linked question. The console window (in VS 2010) disappears immediately after running the program. I use a cin.get(); at the end of the main function, but the problem still remains. Any idea about the possible reason? You can check out the code in main: int main() { const int arraysize = 10; int order; int counter; int a[arraysize] = {2,6,4,45,32,12,7,33,23,98}; cout<<"Enter 1 to sort in ascending order\n" <<"Enter 2 to sort in descending order\n";

c# loop until Console.ReadLine = 'y' or 'n'

别说谁变了你拦得住时间么 提交于 2019-12-02 09:41:54
I'm fairly new to c#, and writing a simple console app as practice. I want the application to ask a question, and only progress to the next piece of code when the user input equals 'y' or 'n'. Here's what I have so far. static void Main(string[] args) { string userInput; do { Console.WriteLine("Type something: "); userInput = Console.ReadLine(); } while (string.IsNullOrEmpty(userInput)); Console.WriteLine("You typed " + userInput); Console.ReadLine(); string wantCount; do { Console.WriteLine("Do you want me to count the characters present? Yes (y) or No (n): "); wantCount = Console.ReadLine();

Why is this only returning “yes”

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 09:21:35
int OnLoad() { cout << "Hi whats your name? "; cin >> name; system("cls"); cout << "Hi " << name << "." << " Are you here to Take Over the city from zombies?"<< endl; cin >> userInput; if (userInput == "yes" || "Yes") { cout << "Yes" << endl; } else if (userInput == "no" || "No") { cout << "No" << endl; } else { cout << "I don't understand." << endl; } return 0; } int main() { OnLoad(); system("pause"); return 0; } This code only returns Yes back, after the console window pops up and ask are you here to take over the city from zombies even after i type no it returns yes! if (userInput == "yes"

How to read user input in c# console

淺唱寂寞╮ 提交于 2019-12-02 09:21:31
问题 I guess this should be very simple to you guys, but very difficult to me because im new to c#. I have a simple "pacient" class. public class Pacient { public Pacient(string _name, string _lastName, DateTime _date, string _phone, string _email) { name = _name; lastname = _lastName dateOfBirth = _date; phone_num = _phone; email = _email; } private string name; public string Name { get { return name; } set { name = value; } } etc... Now i want to read the input user types in console... How do i

Batch script: save stdout and have the output in the console too

邮差的信 提交于 2019-12-02 08:27:46
By default the output of commandline applications is presented in console window and I know that using > or >> we can re-wrire/append the stdout to an external file but what if the commandline application doesn't have internal logging facility to save the output. I want the stdout to be both in the console and be saved in an external file. Is such a thing possible? Try something like this: @echo off echo hello > log.txt & type log.txt pause But using this you can only have one command-output in the log-file at once. You could try it with >> but that way you get the outputs of all commands

Project Unavailable in Visual Studio 2010 Solution

人盡茶涼 提交于 2019-12-02 08:25:01
I created the tool below to create a VS2010 Solution using existing project folders from our non-Microsoft version control. When the code runs, you tell it what folder your code is in, what folder your solution needs to go to, then accept the solution name to create in the folder you pick. It was working OK for a while, until I made some changes to allow for multiple Projects within the same Solution, but now it is broken. No error messages are thrown, so I am having difficulty isolating what the issue is this time. using System; using System.Collections.Generic; using System.Linq; using