C++ :: Read Text File Char By Char By Using Vector Class

Oct 29, 2014

Code:

cout<<"Enter Filename for input e.g(inp1.txt .... inp10.txt):"<<flush;
cin>>filename;
ifstream inpfile;
inpfile.open(filename,ios::in);
if(inpfile.is_open())

[Code] .....

View 8 Replies


ADVERTISEMENT

C++ :: Read Text File - First Line Has Extra Char

May 21, 2012

When I read a text file. I'm reading a list of strings in text file, with one string per line. The first line has extra characters in the string, the rest of the lines read are fine, and I can't understand where the extra characters come from. The file format is this...

A
AA
AAN
AAP
AAPL
AAWW
AAXJ
....
...

Code:
std::vector<std::string> strSymbolList;
std::string s = "";
std::ifstream infile( m_strFileSymbols );
while( std::getline(infile, s) ) {
strSymbolList.push_back(s);
}
infile.close();

View 3 Replies View Related

C++ :: Transform TXT File To Char Vector?

Aug 17, 2013

I need to transform a .txt file to a char vector, but how to do it. as much as I could until now been transformed into vector string.

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

[Code].....

View 7 Replies View Related

Visual C++ :: Read A File Which Is 51563 Char Long?

Nov 15, 2014

I'm trying to read a file which is 51563 char long ( a jpeg pic )

but whenever I open it :

Code:
std::ifstream ifs(file);
std::string pub((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
cout << pub;

I only get like 500 chars, so I tryed a lot of different funcs until I finally realized that they reached the end of file "early" well it thinks that one of the chars in it is an end of file and it's located at the start. So I really don't know what to do with it because every func doesn't see the rest of the file at all.

View 7 Replies View Related

C++ :: Reading In Text File Into Char Array

Oct 17, 2014

I have a project which is about linked lists in the order of: a Story is made of Paragraphs which is made of Sentences which is made of Words. We must treat Words specifically as character arrays, not strings. So I need to read in a story from a text file and make Words by finding the first whitespace/punctuation(everything before the whitespace up until the whitespace or punctuation is the Word), all the Words up to the punctuation are a Sentence (Sentence is a linked list of Words), Paragraph is all the Sentences up until an empty line, and a Story is all the Paragraphs. So I know doing this will let me take a line and put it into a character array:

char charArray[25]; //we are allowed to assume a word won't be longer than 25 characters
int i = 0;
ifstream myFile(fileName.c_str());
if(myFile.is_open()){

[Code].....

I suppose I could look at charArray[i] and if it is ws or punctuation then make the Word = charArray[i-1], but is there an if statement I could do that would prevent the ws or punctuation from being read into charArray in the first place? Because a problem I see with the charArray[i-1] method already is that "This is a story." would get put into the array as Thisisastory. and thus I'd be unable to break up at a space.

So to summarize: I want to read in a text file character by character into a char array, which I can set to length 25 due to context of the project. I want to read in each character and at a whitespace or punctuation, I want to take everything already in charArray and feed that into a Word object constructor (the next Word gets linked to the previous Word, and at a punctuation all the Words linked together become one Sentence, and all the Sentences linked before an empty line become a Paragraph, etc). So how can I get charArray to be only characters in a word, then after the word being read-in ends, charArray resets to empty, and then is populated by the next word and so on.

View 2 Replies View Related

C++ :: Store Contents Of Text File Into Char Array?

Apr 22, 2014

I am trying to store the contents of a text file into a char array. However the function i am using ifstream member function get(); seems to stop working when fed with certain characters. Is there another solution besides the get() function that will accept all types of characters from files?

char text[1000];
for (int i = 0; i <= textlen; ++i)
{
text[i] = text_in.get();
}

View 3 Replies View Related

C++ :: Read Byte Of Char Data And Convert It Into Text String Of Binary Data That Represents Hex Value

Dec 26, 2013

I am writing a program where I need to read a byte of char data and convert it into a text string of binary data that represents the hex value...

i.e. The char byte is 0x42 so I need a string that has 01000010 in it. I've written the following subroutine....

------------- My Subroutine ----------------------------------------------------------------------
void charbytetostring(char input, char *output){
int i, remainder;
char BASE=0x2;
int DIGITS=8;
char digitsArray[3] = "01";

[Code] ....

When I submitted the byte 0x42 to the subroutine, the subroutine returned to the output variable 01000010... Life is good.

The next byte that came in was 0x91. When I submit this to the subroutine I get garbage out.

I am using a debugger and stepped through the subroutine a line at a time. When I feed it 0x42 I get what I expect for all variables at all points in the execution.

When I submit 0x91 When the line remainder = input % BASE; gets executed the remainder variable gets set to 0xFFFF (I expected 1). Also, when the next line gets executed..

input = input / BASE; I get C9 where I expected to get 48.

My question is, are there data limits on what can be used with the mod (%) operator? Or am I doing something more fundamentally incorrect?

View 6 Replies View Related

C++ :: Reading Two Words Into Single Char Array From Text File

Sep 15, 2014

I am trying to read in player names (ex: first last) from a text file into the people[].name data struct. I can successfully read in my card file, but I cannot get this to work. I get a seg fault. I believe this is because nothing is actually being read in for my while loops. I can't use std::strings so these must be c-style strings aka char arrays.

// deck of cards
// below are initializations
#include <iostream>
#include <fstream>
#include <ctime>
#include <stdlib.h>
#include <string>

using namespace std;
//globals
const int maxCards = 52;

[Code] .....

View 1 Replies View Related

C++ :: Dynamic Memory (array Of Char) - Delete All White Spaces In Text File

Feb 8, 2014

General Purpose: Delete all "white spaces" in text file, until the read-in char is _not_ a whitespace (mark as start of text file).

Problem: Cannot seem to shift char's over properly. (I think my problem is the inner loop - however other code may lead to this problem - I do not know)

Code:

#include <fstream>
#include <iostream>
using namespace std;

bool trimWhiteSpace(fstream &file, char * charMemoryBlock) {
if (!file.is_open()) {

[Code] ....

View 3 Replies View Related

C++ :: How To Read CSV File With Own Vector Class

Jul 7, 2014

Input file:

Course Of Sales.csv
Time,Price ($),Volume,Value ($),Condition
10/10/2013 04:57:27 PM,5.81,5000,29050.00,LT XT
10/10/2013 04:48:05 PM,5.81,62728,364449.68,SX XT
10/10/2013 04:10:33 PM,.00,0,.00,

How to read the csv file with my own vector class. I already have date.h,date.cpp,time.h,time.cpp

How to do the maintest and how to create the vector class

I need to show Date, highest price and Start time(s) of the highest share price

View 3 Replies View Related

C++ :: Read Info From Text File Into Class?

May 22, 2014

I'm having trouble in getting my program to read from a file and put all the proper data into its proper class variables. I have a class (called Champion) that has string variable for a name and a vector of strings for items. I also have a vector of Champion that holds multiple champions. Here's my code:

Champion.hpp
#ifndef CHAMPION_HPP_INCLUDED
#define CHAMPION_HPP_INCLUDED
#include <iostream>

[Code].....

View 3 Replies View Related

C++ :: How To Concatenate Two Vector Char

Dec 1, 2013

This seamed as a simple thing but i am getting something i did not expect: Example:

Code:
vector<char> StrJoin(SubjSeq.size()+ QuerySeq.size());
cout << StrJoin.size()<<"
"; // size x

StrJoin.insert( StrJoin.begin(), QuerySeq.begin(), QuerySeq.end() );
StrJoin.insert( StrJoin.begin(), SubjSeq.begin(), SubjSeq.end() );

cout << StrJoin.size()<<"
"; // x*2

All structures are vector<char>. when i do the above my characters form Query and Subject are copied in my new vector called StrJoin but the size of that vector is twice the size then it should be.

View 3 Replies View Related

C++ :: How To Make Vector Of Char

Jun 8, 2013

let say

char temp[8][8];

and you want to make vector of this char

vector<????> boardVec;

View 2 Replies View Related

C++ :: String To Multidimensional Char Vector

Feb 3, 2013

I was working on a program which compares sequences of characters, counts the differences between them, and displays them. I had the sequence inputted as a string (into a vector so any number of sequences could be chosen), and then, the way I tried to check the strings for differences, was by converting the string to a (multidimensional) vector of chars:

vector< vector<char> > sequencesC;
for (int a = 0; a < sequenceCount; a++) {
cout << "
Enter sequence " << a+1 <<" name: ";
cin >> sequenceNames[a];
cout << "

[code]....

However, it crashes (as shown above) when I try to set, by a for loop, every char of a multidimensional vector (sequencesC) to the same char of the data vector. Is there any way I can convert the string to a char vector?

View 7 Replies View Related

C/C++ :: Sending Char And Storing It In Vector

Feb 3, 2014

I've got something I'm trying to accomplish, but crashes my program.

I've got my server and client code.

Having the client send a message they type (char Chat[1024]) And the server receiving the chat (char recv_chat[1024]) only to send it to all connected clients again. Which the server sends the recv_chat.

The client receives it (char recv_chat[1024]). This works, and the client gets the right info. However, I'm trying to store it using a vector. I'm sure I've tried any way possible.

Client storing vector pseudo-code:

vector<char*> SaveChat;
int main () {
while (true) {
if (newClientConnected) {

[Code]....

This doesn't work, and crashes my application. I've tried changing the vector to string, const char*, basically anything I can with no avail.

View 8 Replies View Related

C/C++ :: How To Get Last Line 10 Char In Text File If Last Line Is Null

Aug 24, 2013

I can able to get the last line ten chars but i cant get if the last line is null.

here is my code

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

[Code] ....

here with i have enclosed my file where i am pick my last ten chars ...

Attached Files : log.txt (4.8 KB)

View 1 Replies View Related

C++ :: Comparing Char Array To Char Always Returns True

Dec 23, 2014

I've made a code to check whether or not a save file has been created correctly, but for some reason it always returns this line: readdata[qa]=='1' as true. in which qa is the counter I use in a for loop and readdata is a character array consisting of 50 characters that are either 0, 1 or 2.

this is the entire code:

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

[Code]....

at first is also went wrong at line 22 and also returned that as true, but then I added brackets and it worked.

View 4 Replies View Related

C++ :: Concatenate Two Char Arrays Into Single Char Array?

Sep 29, 2014

I am trying to concatenate two words from a file together. ex: "joe" "bob" into "joe bob". I have provided my function(s) below. I am somehow obtaining the terminal readout below. I have initialized my memory (I have to use dynamic, dont suggest fixing that). I have set up my char arrays (I HAVE TO USE CHAR ARRAYS (c-style string) DONT SUGGEST STRINGS) I know this is a weird way to do this, but it is academic. I am currently stuck. My file will read in to my tempfName and templName and will concatenate correctly into my tempName, but I am unable to correctly get into my (*playerPtr).name.

/* this is my terminal readout
joe bob
<- nothing is put into (*playerPtr).name, why not?
joe bob joe bob
seg fault*/
/****************************************************************/
//This is here to show my struct/playerInit

[Code]....

View 2 Replies View Related

C++ :: Print Linked List But As A Vector Of Char

Aug 26, 2013

I was assigned to print a linked list but as a vector of char (I cannot use the normal string type) , this is what I have:

char* List::asString(){
Node* ite = new Node();
ite= first;//ite is like an iterator of the list
for(int i=0; i<sizeOfList; ++i){//sizeOfList is the total of node of the list

[Code] ....

But when I print that, I get a bunch of weird symbols...

View 7 Replies View Related

C++ :: Deleting Vector With Char - Segment Fault

Apr 19, 2012

The below code is giving me segment fault during delete [] (*iter) sometimes. Is it not the proper way to delete the vector with char *

Code:
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<char*> nameList;
for (int i=0;i<1000;++i)

[Code] ....

View 7 Replies View Related

C/C++ :: Read And Print A Char Array

Nov 25, 2014

In this project I need to develop few functions to work with graphics card. I work in minix and this is pretty rubbish.

I'm having an hard time to read a pixel map, or atleast ro print it on my main function.

I have a read_xpm function, which is given, therefore, working.

char *read_xpm(char *map[], int *wd, int *ht)

then I have a pixmap.h file which gives some examples of pixmap images that I can use as example:

static char *pic1[] = {
"32 13 4",
". 0",
"x 2",
"o 14",

[Code]....

I tried something like read_xpm(xi, yi, *xpm[0]); but I'm guessing I need to index that array and run all those chars in order to show them.

View 3 Replies View Related

C++ :: Char Vector - Fixed Size Two Dimension Array

Jun 9, 2013

I want to save the char[8][8] // fixed size 2 dimension array

to a vector

such as

vector<?????> temp;

is there anyway to approach this?

View 4 Replies View Related

C :: Char Array With A Phrase To Char Word

Nov 28, 2013

I need to do a function that copy every word from a text to a char word. How can i do it?

View 5 Replies View Related

C++ :: Store Address Of Customer In Char Variable - How To Read A Line With Spaces

Oct 10, 2014

I want to store the address of a customer (with spaces) in a char variable (say cadd). First I tried to use "cin", as we know it reads until it sees any whitespace. So it reads only first word before a white space. So, I used "getline()" function, it will work. But when I used it, It did'nt wait for the I/P (it skipped it).

char cadd[20];
std::cout<<"Enter Customer Address:
";
std::cin>>cadd;
std::cout<<"Enter Customer Address:
";
std::cin.getline(cadd,20);

View 3 Replies View Related

C++ :: How To Convert Char To Const Char

Jun 3, 2013

I have a file which contains a year and the name of an associated file to be read. I need to extract the data in the txt file and perform some calculations.

( year data file)
2004 2004data.txt
2005 2005data.txt
2006 2006data.txt

Here is what I do. I first declare "char yeardata" and then pass "2004data.txt" to it. Then I call yeardata in ifstream to extract the data inside the file "2004data.txt". The problem is that char yeardata is not constant so I cannot pass the file to it. It doesn't work if I change "char yeardata" to "const char yeardata".

Code:
int oldnewcomp_temp(char* lcfile) {
using namespace std;

int year;
char yeardata;

[Code] ....

View 12 Replies View Related

C++ :: Dynamic Char Array For Class Constructor

Nov 14, 2013

I'm writing a class that has two constructors. However, I can't get them to work quite right. One constructor has a parameter of an int (with a default value of 0) and the other has a parameter of a C-style string.

First of all, are these function prototypes correct for the constructors?

MyInt(int n = 0);// first constructor, int param, default value 0
MyInt(const char * c);// second constructor, c-style string param

Both constructors work fine in some cases but don't work in all cases. Here are some potential calls to these functions that are supposed to work:

// These two work fine
MyInt x(12345),
y("9876543210123456789"),
// The array assignment doesn't work when the value is negative
// I'm not allowing negative numbers, but I want to create the object and assign the array to 0
r1(-1000),

[Code] .....

Here's the private data from the class (from the header file):

private:
int currentSize,
maxSize;
char* digits;// Pointer to an array of digits

// Increase the size of digits array by 5
void Grow ();

View 2 Replies View Related







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