C++ :: Printing From Open Text File?

Nov 14, 2013

I need to create a text file that looks like:

first line
second line
third line
forth line
fifth line
sixth line

I want to replace the third and forth lines with three new lines. The above contents would become:

first line
second line
new line1
new line2
new line3
fifth line
sixth line

How can I do this using c++?

never was taught file function in c++

View 3 Replies


ADVERTISEMENT

C :: Cannot Open A Text File

Apr 21, 2013

I'm trying to type out whatever is in the .txt document, but I cannot open it for some reason. My code is

Code:
int main(int argc, char *argv[]) {
char ch=0;FILE *fp;
fp=fopen("C:UsersPCDesktopNew folderQuestion 5one.txt",'r');
while(ch!=EOF){
printf ("%c", ch);
ch=getc(fp);
Sleep (200);}fclose(fp);
return 0;
}

I keep getting an error with my fp=fopen so how do you open the text? Do i have anything else wrong with my code.

View 9 Replies View Related

C++ :: Open And Store A Value To Text File

Jan 29, 2014

This my deposit function, i want to open the file (balance), then add the sum and store in on the text file.

float deposit( int x, int currentBalance) {
cout<<"
"<<endl;
cout<<"Welcome to the deposit area"<<endl;
cout << "Your new balance is:" << balance <<endl;

[Code] ....

View 13 Replies View Related

C/C++ :: How To Open Text File From A Specific Location

Feb 2, 2014

I'm having trouble opening a file from a specific location.

#include "maidcafe.h"
....
char directory[80] = {"C:UsersPublicDocumentsAnime NotesTransaction"};
char code[20];
printf("Enter file name");
gets(code);
strcat(directory,code);
system("start "" %s",directory);    

i thought this would work, but it didn't xD. I got an error

View 3 Replies View Related

C++ :: Open Text File From Embedded Resource?

Apr 19, 2014

I have the following complete code in c++

Code:
void GetMapData () {
MapPair NewMap;
string TempString;
BOOL SkipReadLine = FALSE;
//------
char buffer[MAX_PATH];
std::fstream File;

[code].....

The problem is that I do not want to have an external MapData.txt, rather I access it through a embedded text resource, which in this case I have no knowledge on doing so.

I have the following snippet which demonstrates to my knowledge on how to access a text resource; however, I do not know hot to modify the code above to implant this, but to still have the same functionality as the original code above.

Code:
HRSRC hRes = FindResource(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR_TEXT1), _T("TEXT"));
DWORD dwSize = SizeofResource(GetModuleHandle(NULL), hRes);
HGLOBAL hGlob = LoadResource(GetModuleHandle(NULL), hRes);
const BYTE* pData = reinterpret_cast<const BYTE*>(::LockResource(hGlob));

note that I am compiling with a MBCS.

View 2 Replies View Related

C :: Open New Text File With First Letter Of Line On A Certain Directory

May 23, 2013

I'm reading from stdin a line. With that line, I should open a new textfile with the first letter of that line on a certain directory. My code is the following :

Code:

int main() {
char line[BUFSIZ];
FILE *ptr_file;
int x;
while(fgets(line,BUFSIZ,stdin) != NULL){

[Code] ....

char caminho[] is the directory in which I want to create the text file and chave will be the first letter of the line in stdin.

How am I supposed to use strcat to get these two together in a string to then use ptr_file =fopen(caminho, "w");

View 3 Replies View Related

C++ :: Open A Text File Then Read Data And Print It Back?

Nov 5, 2013

I am in an "intro" C++ course and am having trouble with a section of my current project.

We are required to open a text file, read the data from that file, and print it back.

However, we are supposed to let the user input the name of the file that is to be opened. This is the code I have so far. It is not opening anything.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const int NUM_QUESTIONS = 30;
typedef char CharArray[NUM_QUESTIONS];
string fileName;

[Code]...

View 2 Replies View Related

C/C++ :: Reading Strings From A Text File And Printing Them

Feb 26, 2015

I need a program that reads the number of lines of a file and then several (max of 20) lines of text from a .txt file so an example of the .txt file is: 2 This is the first string This is string number 2 So it first reads the 2 and then reads the two lines of text. It stores the text in an array of pointers. The code i have so far is:

#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>

[Code].....

It doesnt give me any errors but all it does is keep running and doesnt print anything out kind of like its in an infinite loop although i dont see how that could be possible.

View 1 Replies View Related

C++ :: Printing Text With Functions

Feb 27, 2014

Any way to make a function that prints something. i wanted to make a function for

Code:

cout << " PAUSE MENU " << endl; cout << " 0. Resume Game " << endl;
cout << " 1. Commands " << endl;
cout << " 2. Controller Setup " << endl;
cout << " 3. Bottles of Beer " << endl;
cout << " 4. Quit " << endl;
cout << " What is your Choice - ";
cin >> userinput;

So i wouldn't have to retype it again in the loop, i would just call the function. but it seems whatever i try it doesn't display the text. i've tried making a function with no return time like this " Void Pausemenu(); " but that just goes blank.

Code:

#include <iostream>
using namespace std;
//This function displays different results based on the users input
int menu(int menuchoice);
int main()

[Code] ....

View 4 Replies View Related

C Sharp :: Open New Cmd From Console Application And Write Text

Oct 23, 2012

I want to open one new CMD from console application, write text into the new CMD and then coming back to the control on the old cmd. (like interactively working on the both)

look into the below code

Process P1 = Process.Start(@"C:WINDOWSsystem32cmd.exe");
P1.StartInfo.RedirectStandardInput = true;
P1.StartInfo.RedirectStandardOutput = true;
P1.StartInfo.UseShellExecute = false;
StreamWriter wr = P1.StandardInput;
wr.WriteLine("First line in New Cmd");
Console.WriteLine("First line in Old Cmd");
wr.WriteLine("Second line in New Cmd");
Console.WriteLine("Second line in Old Cmd");

it is giving the exception "StandardIn has not been redirected"

View 1 Replies View Related

C++ :: Text Editor Printing Algorithms?

Mar 26, 2013

They should apply for: backspace, return, regular char input, vertical scrolling. There is only one buffer, and it is not allowed to side scroll past max col, instead it must scroll down, appending the line cur_y + 1.

View 4 Replies View Related

C/C++ :: Pass Path In File Handling To Create Or Open A File?

Jul 14, 2012

I have a folder "pics" in g: drive. There I want to create some text.txt file. Thus, the final path is "g:pics ext.txt".

How can I do that?

View 3 Replies View Related

C :: Original Text File / Generate Another File With Text Content In Upper Case

Nov 29, 2014

Code software that, from an original text file, generate another file with the text content in upper case.For exemple:

entrence:

luke
tom
alex

outings:

LUKE
TOM
ALEX

My code so far:

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
}

[code]....

View 2 Replies View Related

C :: Printing Contents Of A File - Prints One Extra Character Not Present In The File

Feb 12, 2013

I'm writing a program that stores records into a file and then these records can be printed out. A last name, first name, and score is stored to be exactly 36 characters long (using leading spaces to pad) making it easier to retrieve specific records. For example, three records stored in the file would like like this: (the underscores are simply to illustrate the distance, they are not in the file itself)

_______lastname_______firstname__90__________lname __________fname_100___________last___________first __60

When printed out, the names are formatted as follows:

lastname, firstname: 90
lname, fname: 100
last, first: 60

However, when I print them out this is what I get:

lastname, firstname: 90
lname, fname: 100$
last, first: 60H

For some reason, for any record after the first, an extra character is added to the end. These characters are not in the file, so I was thinking that the array for some reason wasn't being filled completely, (the array is initialized to size 36 and 36 characters are read from the file using fread) so it was printing out a random character assigned to the 36th array position. Except the character never changes, (always a $ for record 2, H for record 3, l for record 4 if i remember) and I've tried reducing the array size or the number of character read and it's the string that gets altered, the random character always remains. I figure the problem must be in the print_records function (appending seems to work no problem). Anyway here is my print records and appending records code.

Code: /*
- Prints a single record stored in the file pointed to by ifp.
*/
void print_record(FILE *ifp, int record) {

[Code]......

View 6 Replies View Related

C++ :: Open Exe File From Program?

Apr 15, 2013

I am wondering how can i open a .exe file with my c++ program. What is the source code?

View 6 Replies View Related

C++ :: Cannot Find Or Open Pdb File

Jan 24, 2013

I'm trying to write a program for a pong game using a tutorial online. Every time i try to run my program its telling me "Cannot find or open pdb file" I have tried running Microsoft visual c++ as administrator and checking the box next to the Microsoft symbol server. I only get a black console screen with a blinking cursor.

View 2 Replies View Related

C/C++ :: How To Open TXT File From Program

Jan 7, 2015

I am fairly new to programming and I am writing a small POS system which in the background creates a receipt. I guess the relevant code would be this:

#include <stdio.h>
int main() {
FILE *receipt;
receipt = fopen("receipt.txt", "w");
fprintf(receipt, "Coffee Bar

[Code] ....

Of course the last bit wont be running for you, since the variables are missing. My question now is, that I like to open this file in a text editor. The file should be opened with a command withing the code. Is that possible at all? As you might can tell the receipt should pop up after the program ran and the user should be able to print it afterwards.

View 6 Replies View Related

C++ :: Input File Won't Open

Dec 2, 2013

For homework I need to take a file of numbers (double) and fine their average. But, I seem to be having an issue just opening the file.

#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
void get_average(ifstream& input_file);
// Precondition: Reads all the numbers from input file stream
// Postcondition: Prints out to the screen the average of the numbers

[code]....

View 3 Replies View Related

C++ :: Unable To Open / Read DAT File

Nov 8, 2013

Reading a .dat file, i'm unable to open the file. This program is for a Air Quality index detector, the AQI machine records the particle concentration every minute and saves it into new data file for each day. So I need to make this program run every minute and convert the concentration in to the AQI readings.

The filename is of the format "ES642_2013-11-09.dat", where ES642 is the software name of the machine, and rest is the year, month and day. The code here is just for the file reading section:

Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

[Code] .....

View 4 Replies View Related

C++ :: Unable To Find Or Open The PDB File

Mar 28, 2014

Code:

'test.exe': Loaded 'C:UsersPcDocumentsVisual Studio 2010Projects estDebug est.exe', Symbols loaded.
'test.exe': Loaded 'C:WindowsSysWOW64
tdll.dll', Symbols loaded (source information stripped).
'test.exe': Loaded 'C:WindowsSysWOW64kernel32.dll', Symbols loaded (source information stripped).

[Code]...

The thread 'Win32 Thread' (0x2d0) has exited with code 1 (0x1).

The program '[6040] test.exe: Native' has exited with code 1 (0x1). my code is not wrong but there is an error which ı dont understand ...where is my error?

View 1 Replies View Related

C++ :: Cannot Open Shared Object File

Nov 11, 2013

i'm writing a lexer, and i want to use boost::regex for it. im sure im using it right (just in case though)

while(!this->Source.empty())
{
if(regex_search(Start, End, Match, regex(""[^"]*""), Flags))

[code].....

someone told me to download the latest source and build that so i did, by unzipping it, cding to the source, running ./bootstrap.sh, ./b2, and finally ./b2 install. when i compile i get no errors but when i run it i get ./jade: error while loading shared libraries: libboost_regex.so.1.55.0: cannot open shared object file: No such file or directory

View 6 Replies View Related

C++ ::  Unable To Open DAT File For Reading

Nov 9, 2013

Need reading a .dat file, i'm unable to open the file

This program is for a Air Quality index detector, the AQI machine records the particle concentration every minute and saves it into new data file for each day. So I need to make this program run every minute and convert the concentration in to the AQI readings.

The filename is of the format "ES642_2013-11-09.dat", where ES642 is the software name of the machine, and rest is the year, month and day.

The code here is just for the file reading section:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(int argc, const char * argv[]) {

[Code] ....

View 5 Replies View Related

C++ :: How To Open A File With Argv As Parameters

Feb 27, 2013

How to open my two files with argv[1] and argv[2] as the parameters . Heres my code:

void computeCalories (const char* nutrientFileName, const char* recipeFileName) {
string file, file2;
ifstream inFile;
cout << "Please enter the nutrient file name

[Code] ....

View 19 Replies View Related

C++ :: Fail To Open / Create A File?

Dec 5, 2014

When I write the Ctor as follows, I get an Error: Invalid Sharing Flag 0 (That happens when file exists or does not exist)

File::File(const string& file)
{
m_file.open(file, std::ios::out, std::ios::app);
}

When I write the Ctor as foolows, I manage to open / create a file.

File::File(const string& file)
{
m_file.open(file);
}

What is wrong with option #1?

note that m_file is a data member of type ofstream

View 1 Replies View Related

C++ :: Unable To Open Include File?

Oct 16, 2013

my programme showing error 'unable to open inclde file ****' i fallowed the general procedure i.e., options-->directories--> ( inclde proper path) still not working..

View 2 Replies View Related

C++ :: Open File Excel Using OLE Automation

Oct 7, 2013

I am trying to open a excel file using ole automation, passin with char * the name.

Code:
void ExcelOpen(char * FileOpenName){
...
{
VARIANT result;
VariantInit(&result);

[Code] ....

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved